.NET: WPF DependencyProperty

DependencyProperty and DependencyObject is the core of WPF data binding.

We can use this two class to binding one class instead of using INotifyPropertyChanged

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.ComponentModel;
 using System.Windows;
 using System.Windows.Data;

 namespace WpfApplication1
 {
     class Student : DependencyObject
     {
         public static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(Student));

         public string Name
         {
             get { return (string)GetValue(NameProperty); }
             set { SetValue(NameProperty, value); }
         }        

         //public BindingExpressionBase SetBinding(DependencyProperty dp, BindingBase binding)
         //{
         //    return BindingOperations.SetBinding(this, dp, binding);
         //}
     }
 }

while the other part can be the same as the code in ".NET WPF DataBinding".

In ease, we can key "propdp" and Tab key to edit every parameter in the function instead of key all the characters for the function.

Besides, there is one concept called Attached Properties that can attach new properties to existing class. This part can be referenced to the book

上一篇:font拓展字体


下一篇:[19/03/17-星期日] 常用类_Calendar日历类&GregorianCalendar公历日历类