Tweets by @Actipro
Please take some time to learn more about us and our product offerings.
We've made two major enhancements to our PropertyGrid for WPF control that have been highly requested by our customers, which include property change events and better collection editing support. These new features will roll out in the upcoming WPF Studio 2010.1 release.
We've added two new bubbling routed events to the PropertyGrid called PropertyChanging and PropertyChanged. These events are fired before and after a property's value is changed via the PropertyGrid, respectively. The event arguments include the IPropertyDataAccessor that is being set, which can be used to access a variety of information about the underlying property (i.e. type, name, value, etc.). In addition, the raw value that is being assigned or was assigned is included in the event arguments. The value is considered "raw" because it may ultimately be converted by the TypeConverter associated with the property.
These events allow you to better track changes made through the PropertyGrid, including capturing undo/redo related information.
In previous versions of the PropertyGrid, collections were presented using the associated TypeConverter. The TypeConverter determines whether a property is expandable and how it is converted to other types, such as a string when displayed in a TextBox/TextBlock. The .NET runtime includes two built-in type converters used with collections. The first is CollectionConverter, which does not allow expansion. This converter is used intrinsically by types that implement ICollection, which includes List<T> and Dictionary<TKey, TValue>. The second built-in type converter is ArrayConverter, which does allow expansion. This converter is used by Array objects, which includes types like string or int.
So out of the box, the PropertyGrid would only allow the expansion of arrays as seen below.
Default display mode of an array, a dictionary, a list, and an observable collection in a PropertyGrid
In the 2010.1 release, the PropertyGrid will continue to default to the behavior described above. But using the new CollectionDisplayMode property you can quickly change how collections are displayed. Collections are defined as types that implement ICollection/ICollection<T>, IList/IList<T>, or IDictionary/IDictionary<TKey,TValue>.
The CollectionDisplayMode.Expandable setting can be used to make all collections expandable. To perform this magic, we leverage a custom type converter that handles collections better than ones built into .NET.
Expandable display mode of an array, a dictionary, a list, and an observable collection in a PropertyGrid
The CollectionDisplayMode.EditableInline setting can be used to display inline editing buttons. These buttons can be used to add or remove items from the associated collection. The PropertyGrid is smart enough to show or hide these buttons based on whether the collection is read-only or of a fixed size. In addition, it determines whether it can instantiate an instance of the "element type" of the associated collection. For example, if you have a list of MyClass objects and MyClass does not have a default constructor, then the add button will not be visible.
EditableInline display mode of an array, a dictionary, a list, and an observable collection in a PropertyGrid
Of course, you can always customize this behavior. You can extend our collection type converter and customize how and when items are added or removed. You could specify that the first 2 items in a list should be read-only and cannot be removed, or manually construct items to be added to a list.
In addition, to the hooks described above we offer four new bubbling events on the PropertyGrid control. The PropertyChildAdding/PropertyChildAdded events are fired before and after a child item is added to a collection. As with the property events described above, you have access to the IPropertyDataAccessor associated with the collection, as well as the item (being) added. The PropertyChildAdding can be used to cancel the operation or update/modify the item being added, maybe using user input collected from a dialog.
Conversely, the PropertyChildRemoving/PropertyChildRemoved events are fired before and after a child is removed from a collection. Again, you have access to the IPropertyDataAccessor associated with the collection and the IPropertyDataAccessor associated with the item being removed. PropertyChildRemoving also allows you to cancel the removal operation.
We hope everyone likes the new features and finds them useful. They open up new usage scenarios for the product. Again, the new features will be available in the upcoming WPF Studio 2010.1 release.
April 27, 2010 at 15:54
Pingback from topsy.com
Twitter Trackbacks for Upcoming PropertyGrid for WPF enhancements: events and collection editing [actiprosoftware.com] on Topsy.com
July 1, 2010 at 01:58
Actipro Blog 2010 Q2 posting summary
Actipro Blog 2010 Q2 posting summary
The Actipro Blog - WPF and WinForms Development