DependencyProperty and DependencyObject is the core of WPF data binding.
We can use this two class to binding one class instead of using INotifyPropertyChanged
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.ComponentModel; 7 using System.Windows; 8 using System.Windows.Data; 9 10 namespace WpfApplication1 11 { 12 class Student : DependencyObject 13 { 14 public static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(Student)); 15 16 public string Name 17 { 18 get { return (string)GetValue(NameProperty); } 19 set { SetValue(NameProperty, value); } 20 } 21 22 //public BindingExpressionBase SetBinding(DependencyProperty dp, BindingBase binding) 23 //{ 24 // return BindingOperations.SetBinding(this, dp, binding); 25 //} 26 } 27 }
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
时间: 2024-11-02 14:52:36