WPF 依赖附加属性
2024-09-08 10:48:15
附加属性的本质是一个依赖属性,与普通的依赖属性区别:
1:注册方法名不一样,如 DependencyProperty.RegisterAttached
2:没有普通的属性包装器,而是通过get和set属性来实现属性包装
3:没有普通的.NET属性
public static readonly DependencyProperty KeepAliveProperty = DependencyProperty.Register(
"KeepAlive",
typeof(bool),
typeof(Window),
new PropertyMetadata(KeepAliveChanged));
/// <summary>
/// 获取一个值,该值指示是否在现代化框架实例中保持指定对象的活动状态/// </summary>
/// <param name="o">The target dependency object.</param>
/// <returns>Whether to keep the object alive. Null to leave the decision to the ModernFrame.</returns>
public static bool? GetKeepAlive(DependencyObject o)
{
if (o == null) {
throw new ArgumentNullException("o");
}
return (bool?)o.GetValue(KeepAliveProperty);
} /// <summary>
/// 设置一个值,该值指示是否在现代化框架实例中保持指定对象的活动状态/// </summary>
/// <param name="o">The target dependency object.</param>
/// <param name="value">Whether to keep the object alive. Null to leave the decision to the ModernFrame.</param>
public static void SetKeepAlive(DependencyObject o, bool? value)
{
if (o == null) {
throw new ArgumentNullException("o");
}
o.SetValue(KeepAliveProperty, value);
}
private static void KeepAliveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var window = d as Window;
if (window != null)
{
window.DialogResult = e.NewValue as bool?;
}
}
用法:
最新文章
- 记住 MVC里用formcollection接收form表单传来的值,表单属性必须有name为健!
- keepalived+nginx高可用负载均衡环境搭建
- Android应用安全之Content Provider安全
- 如何添加WebService调用时的用户认证
- EF6数据迁移
- [Angular 2] Using a Reducer to Change an Object&#39;s Property Inside an Array
- 关于UIText换行
- 2013 吉林通化邀请赛 Play Game 记忆化搜索
- Akka FSM 源代码分析
- Ubuntu 下的环境变量配置
- 关于JS前台计算四舍五入的问题
- redis_简单动态字符串
- SJCP认证题前五十题填坑
- 手机端网页技术--使自己做的asp.net网页适应手机浏览
- Linux系统重置root用户密码
- JDBC查询数据实例
- LeetCode--168--Excel表列名称
- UI基础:target...action设计模式,手势识别器.UIimageview
- 20165233 2017-2018-2 《Java程序设计》第八周学习总结
- nodejs 接收上传的图片
热门文章
- HBaseRegionServer宕机数据恢复
- Redis 系列
- ubuntu下MySQL的安装及远程连接配置(转)
- CSS div内放长英文字母或长数字自动换行 CSS一行排不下自动打断换行
- windows自动关机(任务计划程序 + exe文件)
- 爬虫示例--requests-module
- go语言从例子开始之Example18_1.结构体中定义方法
- CSS中强大的EM(转)
- 解决error: Microsoft Visual C++ 14.0 is required 问题
- 人生苦短_我用Python_str(字符串)_001