PropertyGrid
控件对于在运行时编辑对象非常有用。PropertyGrid:从CollectionEditor获取PropertyValueChanged通知
Form form = new Form();
form.Parent = this;
form.Text = "Editing MyMemberVariable";
PropertyGrid p = new PropertyGrid();
p.Parent = form;
p.Dock = DockStyle.Fill;
p.SelectedObject = _MyMemberVariable;
p.PropertyValueChanged += delegate(object s, PropertyValueChangedEventArgs args)
{
_MyMemberVariable.Invalidate();
};
form.Show();
正如你所看到的,我使用的是PropertyValueChanged
通知弄清楚何时更新_MyMemberVariable
:我如下使用它。但是,_MyMemberVariable
是我没有写的类,其中一个成员是Collection
类型。 PropertyGrid
调用Collection Editor来编辑此类型。但是,收藏编辑器关闭时,我没有收到PropertyValueChanged
通知。
显然,我可以通过使用ShowDialog()
解决此问题,并在对话框关闭后使_MyMemberVariable
无效。
但是,我希望在编辑收藏集时实际获取PropertyValueChanged
事件。有没有办法做到这一点,而不修改_MyMemberVariable
(我没有访问其源代码)?