要通過PropertyGrid實現(xiàn)動態(tài)屬性編輯,可以通過以下步驟實現(xiàn):
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實現(xiàn)動態(tài)屬性編輯。