属性:Property

 

C# 的属性对应一个Field,并且实现了Get和SET方法的封装。

 

 

依赖属性(Dependency Property):

1.节省内存开销

2.使用Binding依赖于其他对象

 

依赖属性使用动态内存分配,在需要的时候进行分配,不需要则不进行分配。

依赖属性所属的对象是依赖对象,wpf所有的控件都是依赖对象。

WPF属性

依赖对象是一个非常底层的类。

 

自定义依赖属性:

public static readonly DependencyProperty TestProperty =

            DependencyProperty.Register("Test", typeof(MainWindow), typeof(MainWindow),

                new FrameworkPropertyMetadata("", new PropertyChangedCallback(_PropertyChanged)));

 

        public string Test

        {

            get

            {

                return base.GetValue(MainWindow.TestProperty).ToString();

            }

            set

            {

                base.SetValue(MainWindow.TestProperty, value);

            }

        }

        public static void _PropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)

        {

 

        }

相关文章:

  • 2021-05-16
  • 2021-12-10
  • 2021-10-18
  • 2021-06-03
  • 2021-06-19
  • 2021-10-06
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2021-10-22
  • 2021-06-29
  • 2021-08-08
  • 2021-07-07
相关资源
相似解决方案