要通过PropertyGrid实现动态属性编辑,可以通过以下步骤实现:
public class CustomObject : INotifyPropertyChanged
{
private string _name;
public string Name
{
get { return _name; }
set
{
_name = value;
OnPropertyChanged("Name");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
CustomObject customObject = new CustomObject();
propertyGrid1.SelectedObject = customObject;
通过这种方式,就可以通过PropertyGrid实现动态属性编辑。