Notification Support for WPF Property Grid with Dictionary

Grids for WPF Forum

Posted 3 months ago by Jamie Godbout - Owner, Godbout PCS LLC
Version: 23.1.4
Avatar

I am trying to use the your WPF property grid with a custom class of which has a member that is a dictionary<string, string>. However, dictionaries do not implement the INotify interface and your component does not allow me to add new items to the dictionary at runtime. My work around is to create a new diaglog where I can add new key value pairs to the dictionary. If I add a break point I can see the new entry in the dictionary, but it doesn't get reflected in the property grid.

I have tried to create a new class that impliments the INotify and IDictionary interface to get the property grid to update, however, when I do this, the propery doesn't expand properly. All I see is a count of the number of element in my dictionary.

I assume I am missing some property that the property grid requires to expand properly.

So my question is:

Is there a way that I can trigger the property grid to update the dictionary property after I add a new key value pair?

Is there already an established way to manipulate dictionaries using your property grid that I am missing? If so could you provide an example?

I essentially need something to hold <string, string> pairs that I can add, remove, or update from the grid.

How does the property grid enable the property to be expanded? The documentation says that it needs to implement IDictionary, ICollection, or IList interfaces, which my observableDictionary class does, but it doesn't display propery like it does if I directly tie the dataobject to the dictionary.

Thank you

Jamie

Jamie Godbout

Comments (3)

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jamie,

Our "Dictionary Data Factory" QuickStart in the samples project shows editing of a Dictionary<string, string> class and does allow adding/removing items via the PropertyGrid.  However as you said, dictionaries don't implement INotifyPropertyChanged so they can't be monitored for external changes, out of the box at least.

Microsoft has an ObservableDictionary implementation here:

https://referencesource.microsoft.com/#PresentationFramework/src/Framework/MS/Internal/Annotations/ObservableDictionary.cs

I'm not sure if that would work better for notifying external changes.  

Each IPropertyModel has a Refresh method that can be called to invalidate a specific property.

Or at an even higher level, the PropertyGrid control has a Refresh method that will fully rebuild the tree.  That's something that could be called as an extreme fallback if needed.

Expandability comes from the presence of a ExpandableObjectConverter in the TypeConverter of a property.  Our data factory looks for that type converter and if found, will get child properties to add as children of the IPropertyModel.

I hope that helps!


Actipro Software Support

Posted 3 months ago by Jamie Godbout - Owner, Godbout PCS LLC
Avatar

Thank you this was very helpful. Can you provide me with a link to the sample projects? I am having trouble finding them on your website?

Jamie Godbout

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jamie,

If you run our WPF Controls installer (from our Downloads page or from your account page if you are licensed), it will install the samples project.

It's also fully open source on GitHub:

https://github.com/Actipro/WPF-Controls/tree/develop/Samples/SampleBrowser


Actipro Software Support

The latest build of this product (v24.1.2) was released 4 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.