的PropertyDescriptor和WPF绑定mechinsm [英] PropertyDescriptor and WPF Binding mechinsm

查看:138
本文介绍了的PropertyDescriptor和WPF绑定mechinsm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景



我调查了一些代码和遇到含的DataGrid 与一些绑定列的XAML:

 绑定={结合calc_from}...... 

我到处寻找,但没有包含一个名为属性 calc_from 无类。
然后,我偶然发现了一些的PropertyDescriptor 类。我想,这是他们如何绑定工作,但并没有完全了解。



问题



什么是的PropertyDescriptor 又是什么好?
我什么时候想实现自己的 CustomTypeDescriptor
和它是如何涉及到WPF绑定机制?



我来翻过中的这个线程,但我会很高兴,如果有人将它提供一些线索


< DIV CLASS =h2_lin>解决方案

什么是PropertyDescriptor的又是什么好?



PropertyDescriptor的是一个抽象类,它提供基本都是在Binding类内部使用一些方法和属性。例如WPF有那些正常的属性和依赖属性,因此不绑定使用了普通的人构造一个PropertyDescriptor和从PropertyDescriptor的继承和覆盖其抽象方法,如DependencyPropertyDescriptor 的SetValue,的GetValue,ResetValue..etc 。 Futhermore这些的PropertyDescriptor提供了一种机制来听PropertyChanged的事件,如果主阶级的实际财产已INotifyPropertyChanged的实施。综上所述,当我们谈论绑定在WPF再有就是在对模型类单面上设置在另一侧的所需属性的PropertyDescriptor。



将我的当想实现自己的描述符?



我现在能想到的唯一例子是,当你不能在你的实体类实现INotifyPropertyChanged无论出于什么原因,你必须做一些投票站的询问或更改属性,那么你会写自己的PropertyDescriptor做那种轮询一个属性要求它的每一个1/100一秒钟的价值。如果你告诉绑定使用自定义PropertyDescritor,你就会有一个PollingBinding级。



另一个例子是DelayBinding有些人写到这里在互联网上中同时具有自定义的PropertyDescriptor与绑定,您计数希望多久设置一个属性的值,如果你想设置的值1000倍于1/100秒,那么这件事将让你虽然每10个这样做的时间,所以它会为您提供一个小的延迟。



从您发布我们链接的例子是另一个很好的例子。在这个问题的人希望有自己的定制类型说明符管理其自己的自定义更改通知。这就是的PropertyDescriptor来得心应手。



PropertyDescriptor的通常工作与约束力。这本身就是相当转储。 :)


Background

I am investigating some code and encountered a xaml containing a DataGrid with some binded columns:

Binding="{Binding calc_from}" ....

I've search everywhere but there is no class containing a property called calc_from. Then I stumbled upon some PropertyDescriptor classes. I figured that this is how they make the binding work but didn't fully understand how.

Question

What is PropertyDescriptor and what is it good for? When will I want to implement my own CustomTypeDescriptor? And how does it relate to WPF binding mechanism?

I've came accross an example in this thread but I'd be happy if someone will shed some light on it

解决方案

What is PropertyDescriptor and what is it good for?

PropertyDescriptor is an abstract class providing few methods and properties which are mostly used in Binding class internally. For example WPF has those "normal" properties and the dependency properties and so does Binding use a PropertyDescriptor for the normal ones and a DependencyPropertyDescriptor which inherits from PropertyDescriptor and overrides its abstract methods such as SetValue, GetValue, ResetValue..etc. Futhermore those PropertyDescriptors provide a mechanism to listen to PropertyChanged events if the owner class of the actual property has INotifyPropertyChanged implemented. To sum up when we talking about Bindings in WPF then there is PropertyDescriptor on one side against the model class providing that desired property on another side.

When will I want to implement my own descriptor?

The only example I can think of right now is when you cannot implement INotifyPropertyChanged in your entity class for whatever reason and you have to do some kind of polling to ask or change a property then you will write your own PropertyDescriptor doing kind of polling on a property asking for its value every 1/100 for a second. If you tell the Binding to use your custom PropertyDescritor you will end up having a "PollingBinding" class.

Another example is "DelayBinding" that some guys wrote here on the internet having a custom PropertyDescriptor in combination with Binding which counts how often you wished to set a value on a property and if you trying to set the value 1000 times in 1/100 of a second then that thing will allow you to do so though every 10th time and so it will provide you a small delay.

The example from the link you posted us is another good example. In that question the guy wished to have its own custom type descriptor managing its own custom change notifications. That is where PropertyDescriptor comes handy.

PropertyDescriptor works usually with Binding. That thing alone is pretty dump. :)

这篇关于的PropertyDescriptor和WPF绑定mechinsm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆