码迷,mamicode.com
首页 > Windows程序 > 详细

.NET: WPF DependencyProperty

时间:2015-08-14 15:38:30      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

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 }
View Code

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

.NET: WPF DependencyProperty

标签:

原文地址:http://www.cnblogs.com/yingzhongwen/p/4729890.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!