Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

c# - Updating a PropertyGrid

How can I have a property grid update automatically when the object in its SelectedObject property changes? I've tried implementing INotifyPropertyChanged in my class but the property grid does not actually show the new propertyies of the object in the background until I click on it.

I've tried subscribing to the PropertyChanged event of my object directly, and calling the Refresh() method of the PropertyGrid when it is envoked. But some of my properties are related. Meaning changing one property may evoke multiple PropertyChanged events. This seems to work fine, but I'm still wondering if there is a cleaner way of doing this through DataBinding. Also I'd like to avoid having the control Refresh multiple times after the user only updated a single property.

So is there a way to get the PropertyGrid to refresh from PropertyChanged events?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try adding the RefreshProperties attribute to each property that has dependencies:

[RefreshProperties(RefreshProperties.All)]

Now, each time this property changes - it will automatically refresh the other fields. This is a much cleaner approach than calling the property-grid's "Refresh()" each time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...