This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, Here is the issue I am facing for which I am attaching a sample project. I want to use a custom ComboBoxEditor for a property of type List<String>. When I have a single SelectedObject, the editor is populated with the list of strings as expected and works fine. However, if SelectedObjects property is used, the drop-down list appears blank even if a single object is selected. I am not sure if there is something I am doing wrong. Please help |
|
|
Internally, when you use SelectedObjects, the grid creates an object of type MultipleObjectWrapper to bundle up the objects. This exposes the same properties as the selected objects, but aggregates their values and fans out changes. Now consider how this interacts with your configuration. Your PropertyEditor declaration specifies a PropertyName, but not a DeclaringType: that tells the grid, "any property called ListFriends, on any type, I can handle it!" So when the grid sees a ListFriends property on the multiple object wrapper, it hands it off to your editor template. Unfortunately, what the editor receives is another wrapper object of type Many. ComboBox.ItemsSource has no idea how to bind to a Many and ends up showing an empty list. The solution is therefore to specify that the PropertyEditor only knows how to handle the ListFriends property declared by the Pupil type: <ms:PropertyEditor PropertyName="ListFriends" DeclaringType="{x:Type local:Pupil}" ... /> This will restore the by-design behaviour: when there are multiple selected objects with different lists, the grid will show the "inconsistent values" indicator, but when there is a single item in the multiple-select list, or the items have the same ListFriends value, it will show the drop-down with the correct values. However, please note that "the same ListFriends value" will in this case mean reference equality of the lists. The grid will not check the contents of the lists to see if they are the same. Consequently, unless two Pupils share the same list instance, not just the same list contents, the ListFriends property will always be shown using the "inconsistent values" indicator. So the by-design behaviour may not be want for the list case. If you want an editor which is smart about handling lists from multiple Pupils, you will need to create one and hook it up as follows: <ms:PropertyEditor PropertyName="ListFriends" DeclaringType="{x:Type ms:MultipleObjectWrapper}" ... /> The EditorTemplate in this case receives a Many<List<string>> and can use the Values property to examine the values on the individual wrapped objects in order to merge them or do whatever it wishes. Note that this will also override the case where there is one item in the multiple selection or if the selected pupils share a list instance. (By adding this PropertyEditor you bypass the usual ManyEditor which is normally responsible for displaying the "normal" editor.) Your EditorTemplate can trigger on the IsConsistent value to display different UI in these cases if required. |
|