要通過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實現動態屬性編輯。