WPF与InotifyPropertychanged结合到自定义类
我正在处理WPF应用程序,我尝试在更改儿童属性时通知父类。类关系如上图:
class Class1
{
Class2 c2;
private void OnPropertyChanged()
{
// Do someting When Class3.Property is changed
}
}
class Class2
{
Class3 c3;
}
class Class3
{
string Property
{
get {...}
set
{
...
PropertyChanged();
}
}
}
我知道为此目的有InotifyPropertychanged,但是我只发现了它用于绑定.xAML文件的情况。是否有任何方法可以将自定义类绑定,或者与类似的事情结合
Im working on a wpf application and I try to notify Parent class when Child's property is changed. Classes relations look like above:
class Class1
{
Class2 c2;
private void OnPropertyChanged()
{
// Do someting When Class3.Property is changed
}
}
class Class2
{
Class3 c3;
}
class Class3
{
string Property
{
get {...}
set
{
...
PropertyChanged();
}
}
}
I know that there is INotifyPropertyChanged for this purposes, but I've found only the cases where it is used for binding .xaml files. Is there any way to bind custom classes with it, or with similar thing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非目标是
dependencyObject
(对于非GUI相关类是很少见的),否则您无法绑定简单的类。如果您需要简单的通知,通常会为特定属性或属性实施事件:
You can't bind simple classes unless the target is a
DependencyObject
(which is quite uncommon for non GUI related classes).If you need simple notification, you would usually implement an event for the particular property or properties: