加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

WPF 重要新概念 之 属性依赖的实现

发布时间:2020-12-13 20:06:44 所属栏目:百科 来源:网络整理
导读:依赖属性的实现 public class ButtonTest : ButtonBase { //依赖属性 public static readonly DependencyProperty IsDefaultProperty; public bool IsDefault { get { return (bool)GetValue(ButtonTest.IsDefaultProperty); } set { SetValue(ButtonTest.Is

依赖属性的实现

  public class ButtonTest : ButtonBase
    {
        //依赖属性
        public static readonly DependencyProperty IsDefaultProperty;

        public bool IsDefault
        {
            get { return (bool)GetValue(ButtonTest.IsDefaultProperty); }
            set { SetValue(ButtonTest.IsDefaultProperty,value); }
        }

        static ButtonTest()
        {
            //注册属性
            ButtonTest.IsDefaultProperty = DependencyProperty.Register("IsDefault",typeof(bool),typeof(ButtonTest),new FrameworkPropertyMetadata(false,new PropertyChangedCallback(IsDefaultChanged)));
        }
        /// <summary>
        /// 属性改变时操作
        /// </summary>
        /// <param name="o"></param>
        /// <param name="e"></param>
        private static void IsDefaultChanged(DependencyObject o,DependencyPropertyChangedEventArgs e)
        {

        }
    }
以后补充

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读