附加属性的本质是一个依赖属性,与普通的依赖属性区别:

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?;
}
}

用法:

最新文章

  1. 记住 MVC里用formcollection接收form表单传来的值,表单属性必须有name为健!
  2. keepalived+nginx高可用负载均衡环境搭建
  3. Android应用安全之Content Provider安全
  4. 如何添加WebService调用时的用户认证
  5. EF6数据迁移
  6. [Angular 2] Using a Reducer to Change an Object&#39;s Property Inside an Array
  7. 关于UIText换行
  8. 2013 吉林通化邀请赛 Play Game 记忆化搜索
  9. Akka FSM 源代码分析
  10. Ubuntu 下的环境变量配置
  11. 关于JS前台计算四舍五入的问题
  12. redis_简单动态字符串
  13. SJCP认证题前五十题填坑
  14. 手机端网页技术--使自己做的asp.net网页适应手机浏览
  15. Linux系统重置root用户密码
  16. JDBC查询数据实例
  17. LeetCode--168--Excel表列名称
  18. UI基础:target...action设计模式,手势识别器.UIimageview
  19. 20165233 2017-2018-2 《Java程序设计》第八周学习总结
  20. nodejs 接收上传的图片

热门文章

  1. HBaseRegionServer宕机数据恢复
  2. Redis 系列
  3. ubuntu下MySQL的安装及远程连接配置(转)
  4. CSS div内放长英文字母或长数字自动换行 CSS一行排不下自动打断换行
  5. windows自动关机(任务计划程序 + exe文件)
  6. 爬虫示例--requests-module
  7. go语言从例子开始之Example18_1.结构体中定义方法
  8. CSS中强大的EM(转)
  9. 解决error: Microsoft Visual C++ 14.0 is required 问题
  10. 人生苦短_我用Python_str(字符串)_001