![](/img/trans.png)
[英]Can't bind to DependencyProperty child of DependencyObject
[英]Can't Bind the DependencyProperty of a Class Derived from DependenyObject in WPF?
我有一个名为MyControl的控件,其中包含一个名为MyClasses的Collection < MyClass >
<MyControl>
<MyClasses>
<MyClasss Value={Binding} />
</MyClasses>
</MyControl>
从DependencyObject
派生的MyClass
Public Class MyClass : DependencyObject,INotifyPropertyChanged
{
Value //propdp (DependencyProperty)
}
我有一个DataTable
。 我需要将表[0] [0]中存在的数据与MyClass的Value属性绑定在一起
Binding valuebinding = new Binding();
valuebinding.Path = new PropertyPath("ItemArray[0]");
valuebinding.Source = Table.Rows[0];
valuebinding.Mode = BindingMode.TwoWay;
BindingOperations.SetBinding(myValue, MyClass.ValueProperty, valuebinding);
BindingOperations.SetBinding(textBlock, TextBlock.TextProperty, valuebinding);
现在我需要动态更改数据表中存在的数据的值吗? 有问题吗? 解决方案是否与以下原因有关?
注意:它在Silverlight中工作正常
您最好可以做一件事。 创建一个具有要从dataTable对象设置的属性的类,从INotifyPropertyChanged派生该类,然后从控件绑定该类的属性。 一个小的代码段,如下所示
class MyCodeSnippet:INOtifyPropertyChanged
{
public object MyProperty {
get;
set
{
//Register for Notification
}
}
//Implement all the INotifyPropertyChanged function
}
valuebinding.Path = new PropertyPath("MYProperty");
valuebinding.Source = MyClass;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.