我遇到了 propertyGrid 的问题。
我有一个名为 DummySettings 的类,它映射到 propertyGrid 我有一个属性“名称”
在 propertygrid EG 中键入内容时,我想引发一个“TextChanged”事件
尽管实现了 INotifyPropertyChanged 事件并引发了它,并且尽管在 propertyGrid 上挂钩了我能想到的各种事件,但当 A 文本更改时,这些事件都不会触发。
我错过了显而易见的事情吗?
已编辑
伪代码
public class DummySettings : INotifyPropertyChanged
{
private string name;
[DisplayName("Name")]
public string Name
{
get { return name; }
set
{
if (name != value)
{
name = value;
OnPropertyChanged("Name");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
//UserControl
public partial class DummyControl : UserControl
{
private DummySettings settings;
///Constructor
public DummyControl()
{
InitializeComponent();
settings = new DummySettings();
propertyGrid1.SelectedObject = settings;
settings.PropertyChanged += OnDummyPropertyChanged;
//All the events I have hooked up but not firing when text is changed
private void OnDummyPropertyChanged(object sender, PropertyChangedEventArgs e)
{
btnToEnable.Enabled = HasName();
}
private void propertyGrid1_Leave(object sender, EventArgs e)
{
btnToEnable.Enabled = HasName();
}
private void propertyGrid1_Validating(object sender, CancelEventArgs e)
{
btnToEnable.Enabled = HasName();
}
private void propertyGrid1_SelectedObjectsChanged(object sender, EventArgs e)
{
btnToEnable.Enabled = HasName();
}
private void propertyGrid1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
btnToEnable.Enabled = HasName();
}
private bool HasName()
{
return settings.Name.IsNotNullOrEmpty();
}