This project has moved and is read-only. For the latest updates, please go here.

Can't figure out how to use PropertyGrid

Sep 2, 2014 at 9:16 PM
            <ListView Name="ProductsList" 
                      ItemsSource="{Binding Products}">
                        <GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name"/>
            <GridSplitter Width="5"/>
            <xctk:PropertyGrid Name="ProductPropertyGrid" Grid.Column="1" DataContext="{Binding ElementName=ProductsList, Path=SelectedItem}" AutoGenerateProperties="True"/>
I'm not sure what I'm missing, the above (and every variation I've tried) gives me a blank PropertyGrid with properties..
Sep 3, 2014 at 1:37 PM

Have you try setting the PropertyGrid.SelectedObject property ? The PropertyGrid should display the properties of this object.
Sep 3, 2014 at 2:39 PM
Nope, that was it. Thanks. I was setting the DataContext instead.
Sep 3, 2014 at 2:49 PM
Is there a way to make it so that the PropertyGrid won't show properties with certain attributes? Say I have two property grids hooked up to the same property and I have two separate attributes [ShowInGridOne] and [ShowInGridTwo]. Is there any way to make it so that each property grid only displays their associated properties?
Sep 3, 2014 at 3:38 PM

This attribute doesn't exists.
But when you create your propertyGrid, you can set the properties you want to display. Make sure to set the AutoGenerateProperties to False. This way, one PropertyGrid will show properties A, B an C, while the other propertyGrid can show properties D, E and F.
 <xctk:PropertyGrid x:Name="_propertyGrid"
                         SelectedObject="{Binding MyObject}"
            <xctk:PropertyDefinition TargetProperties="FavoriteColor" />
            <xctk:PropertyDefinition TargetProperties="PetNames" />

 <xctk:PropertyGrid x:Name="_propertyGrid2"
                          SelectedObject="{Binding MyObject}"
            <xctk:PropertyDefinition TargetProperties="FirstName" />
            <xctk:PropertyDefinition TargetProperties="LastName" />
Sep 3, 2014 at 4:02 PM
Edited Sep 3, 2014 at 4:04 PM
Thanks, that doesn't help with dynamically loaded objects, though (meaning I won't know the implementation up front to hard code specific properties to show/not show). It looks like I'll have to dig into it and create a custom property grid on top of what you've provided or go back to our old solution.
Sep 3, 2014 at 6:19 PM
What about doing the above from the code behind? If I can set up the property definitions from the code behind I might be able to do this at run time when my list's selected item changes.
Sep 3, 2014 at 7:00 PM
Yes, you can try it.
If you need to refresh the PropertyGrid, try PropertyGrid.Update().
Sep 4, 2014 at 6:09 PM
If I have a string property in my propertygrid that I intend to be a password field, is there an attribute I can decorate the property with to obfuscate the text?
Sep 5, 2014 at 8:29 PM

We don't have this kind of attribute, but you can vote for this issue :
Adding a passwordTextBox control in the toolkit could be a solution for EditingTemplateDefinition for this specific property in the PropertyGrid.

for now, we only have a maskedTextBox that can be used as a template for a specific property in the PropertyGrid :
<xctk:PropertyGrid x:Name="_propertyGrid">
            <xctk:EditorTemplateDefinition TargetProperties="MyName">
                     <xctk:MaskedTextBox Text="{Binding Value}" Mask="AAAAAAAAAAAAA"/>