后台代码绑定到目标CLR属性 [英] Databinding to a target CLR property in code-behind
问题描述
绑定到依赖项属性在代码隐藏中很容易.您只需创建一个新的 System.Windows.Data.Binding
对象,然后调用目标依赖对象的 SetBinding
方法.
Binding to a Dependency Property is easy in code-behind. You just create a new System.Windows.Data.Binding
object, and then call the target dependency object's SetBinding
method.
但是,当我们要绑定的属性是CLR属性并且您不能为 SetBinding
提供 DependencyProperty
参数时,该怎么办?有没有办法使用CLR属性作为绑定目标?
But how do you do this when the property which we're binding is a CLR property and you can't provide a DependencyProperty
argument to SetBinding
? Is there a way to use a CLR property as a binding target?
(如果相关),该对象实现 INotifyPropertyChanged
.
The object implements INotifyPropertyChanged
, if that's relevant.
推荐答案
绑定目标必须是依赖项属性!这是数据绑定工作的唯一要求!
Binding targets MUST be dependency properties! That's the only requirement for databinding to work!
在此处了解更多信息
- http://msdn.microsoft.com/en-us/library/ms531387(VS.85).aspx
- http://msdn.microsoft.com/en-us/library/ms752347.aspx
这篇关于后台代码绑定到目标CLR属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!