I have a XamPropertyGrid that is displaying properties for multiple objects using the SelectedObjects property. For default controls that represent a property, check box for a bool property for example, the control is able to display an indeterminate state when the properties have both true and false values. How can I accomplish this for my own custom controls I provide in a PropertyGridEditorDefinition? I've provided a sample of one of my definitions below. Thanks!
Hello Richard,The PropertyGridEditorDefinition allows you to customize the editor control which will be used in the XamPropertyGrid control. Since you are using the custom WeightEditor controll defined in your application, it should have the three state support defined in order to display correctly when different values are provided by the Weight type. By default, the bool property could be defined as nullable type which is supported by the Checkbox so that when a null value is provided the Checkbox is in undetermined state.Let me know if you have any questions.
Hi Maria, thanks for your reply but that's not really what I'm asking. I was just giving an example of a check box recognizing multiple values and being set as indeterminate. Another example would be a text box bound to a string property where the objects in the SelectedObjects collection have different values. The behavior of the text box control is to show a blank value. That is what I'm after. How are these controls aware that there are multiple values?
Hello Richard,Thank you for the additional details.When the XamPropertyGrid.SelectedObjects property is set and custom EditTemplate is bound to the Value property, the XamPropertyGrid will use the first element in the array to display it in the PropertyGridPropertyItemView. In the attached sample project that will be David.The default behavior could be changed by binding the custom editor to the SelectedObject:
<ig:PropertyGridEditorDefinition > <ig:PropertyGridEditorDefinition.TargetProperties> <sys:String>FirstName</sys:String> </ig:PropertyGridEditorDefinition.TargetProperties> <ig:PropertyGridEditorDefinition.EditTemplate> <DataTemplate> <TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ig:XamPropertyGrid}}, Path=SelectedObjects, Converter={StaticResource conv}}"/> </DataTemplate> </ig:PropertyGridEditorDefinition.EditTemplate> </ig:PropertyGridEditorDefinition>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { object[] items = value as object[]; string firstName = (items[0] as ClientViewModel).FirstName; if(items != null) { foreach (var item in items) { if ((item as ClientViewModel).FirstName != firstName) return ""; } } return firstName; }