INotifyPropertyChanged的用户控件中 [英] INotifyPropertyChanged in UserControl
问题描述
我有一个从TextBox控件继承的自定义控件。
我想实现我的自定义控件 INotifyPropertyChanged的
接口。
公共类CustomTextBox:文本框,INotifyPropertyChanged的
{
公共事件PropertyChangedEventHandler的PropertyChanged;
保护无效NotifyPropertyChanged(字符串信息)
{
如果(的PropertyChanged!= NULL)
的PropertyChanged(这一点,新PropertyChangedEventArgs(信息));
}
}
我的问题是,当我尝试提出一个PropertyChanged事件PropertyChanged事件处理程序始终为空。
任何人都可以帮我吗?
PropertyChanged事件处理程序alwas空。
块引用>
这将永远是真,直到事情订阅在
的PropertyChanged
事件。
通常,如果你正在做一个自定义的控制,但是,你不会用
INotifyPropertyChanged的
。在这种情况下,你会成为一个自定义依赖属性代替。通常情况下,依赖对象(即:对照)将所有使用依赖属性,INPC使用由成为DataContext的
这些对象的类。这使得绑定系统的正常工作。I have a custom control which is inherited from TextBox control. I would like to implement the
INotifyPropertyChanged
interface in my custom control.public class CustomTextBox : TextBox, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string info) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(info)); } }
My problem is when I try to raised a PropertyChanged event the PropertyChanged event handler is always null.
Anybody can help me?
解决方案the PropertyChanged event handler is alwas null.
This will always be true until something subscribes to the
PropertyChanged
event.Typically, if you're making a custom control, however, you wouldn't use
INotifyPropertyChanged
. In this scenario, you'd make a Custom Dependency Property instead. Normally, the dependency objects (ie: controls) will all use Dependency Properties, and INPC is used by the classes which become theDataContext
of these objects. This allows the binding system to work properly.这篇关于INotifyPropertyChanged的用户控件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!