在WPF中,控件的一些属性是依赖属性,其他属性是普通属性。
例如TextBox.SelectedText
是普通属性而不是依赖属性。我使用MVVM,我常常想要绑定到某些属性,但我不能,因为它是一个普通的属性。
有人可以向我解释一下,决定一个属性是正常还是一个依赖属性的决定背后的逻辑。
另外,我可以解决这个问题并以某种方式绑定到普通属性,就像它们是依赖属性一样吗?
答案 0 :(得分:1)
您可以绑定到普通属性,但如果您的属性发生更改,则不会通知您的绑定。但是,您可以在类中实现INotifyPropertyChanged,绑定将自动更新您的控件。
答案 1 :(得分:1)
浏览这些链接
When to use a WPF Dependency Property versus INotifyPropertyChanged
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/65bf126f-e706-4d3e-8cc3-e0130a0ee6de
http://joshsmithonwpf.wordpress.com/2007/06/22/overview-of-dependency-properties-in-wpf/
WPF: What distinguishes a Dependency Property from a regular CLR Property?
How to set bindings on CLR Properties using DataResource
您将更好地了解您想要找到的内容