This project has moved. For the latest updates, please go here.

PropertyGrid.PropertyDefinitions does not seem to work (for me?)

Feb 9, 2012 at 2:46 PM
Edited Feb 10, 2012 at 7:25 AM

Hey there!

I'm trying to get the PropertyGrid to  work for me, but I'm having some issues with the adding of properties.

I've got the following test code:

public partial class MainWindow: Window
{ 
    public MainWindow()
    {
        InitializeComponent();
    }
} 

public class Person
{
    [Category("Information"), Description("This property uses a TextBox as the default editor."  )]   
    public string Name { get; set ; }   

    [Category("Preferences"), DisplayName("Favorite Color"), Description("This property uses a TextBox as the default editor."  )]   
    public Color FavColor { get; set ; }
}

with the following XAML:

...
<PropertyGridWindow:Person x:Key="person1" Name="test"/>
...
<extToolkit:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10" SelectedObject="{StaticResource ResourceKey=person1}" AutoGenerateProperties="False">
    <extToolkit:PropertyGrid.PropertyDefinitions >
        <extToolkit:PropertyDefinition Name ="FavColor" />
    </extToolkit:PropertyGrid.PropertyDefinitions >
</extToolkit:PropertyGrid >
It still automatically generates the Name and the FavColor property for me in the window.
Can anyone explain me what I'm doing wrong?

Thanks in advance!
//Shane

 

Feb 10, 2012 at 10:54 AM

I do not understand what you really want. But if to hide a property use the tag:

[Browsable (false)] upon the property ..

Now if you want to customize how it will work, use:

                     <extToolkit:EditorDefinition>
                         <extToolkit:EditorDefinition.PropertiesDefinitions>
                             <extToolkit:PropertyDefinition Name="Age" /> 
                             <extToolkit:PropertyDefinition Name="WritingFont" />
                             <extToolkit:PropertyDefinition Name="Spouse" />
                         </ extToolkit: EditorDefinition.PropertiesDefinitions>
                         <extToolkit:EditorDefinition.EditorTemplate>
                             <DataTemplate>
                                 <TextBlock Background="Yellow" Text="{Binding Value}" />
                             </ DataTemplate>
                         </ extToolkit: EditorDefinition.EditorTemplate>
                     </ extToolkit: EditorDefinition>

Remember that all this is only available in version "1.6" you can download only in "SourceCode"

Feb 10, 2012 at 11:06 AM
relmaster wrote:

I do not understand what you really want. But if to hide a property use the tag:

[Browsable (false)] upon the property ..

...


Remember that all this is only available in version "1.6" you can download only in "SourceCode"

Thanks, this fixed my issue.

I was using the 1.6 version from the Main folder in the SourceCode download.
But I guess I misinterpreted the propertydefinition usage.
I expected these definitions to only show the properties I had specified in the

<extToolkit:EditorDefinition.PropertiesDefinitions>
  <extToolkit:PropertyDefinition Name="FavColor" /> 
</extToolkit:EditorDefinition.PropertiesDefinitions>

 part of the XAML. Guess that is only in conjunction with the EditorDefinitions.

 

The [Browsable(false)] was the correct way of excluding properties in the window.

 

Thanks!

//Shane

Feb 10, 2012 at 11:10 AM

You can use the property: "AutoGenerateProperties" and specify false. That will no longerbe generated properties...

Feb 13, 2012 at 7:30 AM
relmaster wrote:

You can use the property: "AutoGenerateProperties" and specify false. That will no longerbe generated properties...

This works, it no longer generates any properties.

However, from the documentation page, I understood the first piece of sample code: 

<extToolkit:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10" AutoGenerateProperties="False">
<!-- Only the following properties will be displayed in the PropertyGrid -->
  <extToolkit:PropertyGrid.PropertyDefinitions>
    <extToolkit:PropertyDefinition Name="FirstName" />
    <extToolkit:PropertyDefinition Name="FavoriteColor" />
    <extToolkit:PropertyDefinition Name="PetNames" />
  </extToolkit:PropertyGrid.PropertyDefinitions>
</extToolkit:PropertyGrid>

to only show the FirstName, FavoriteColor and PetNames columns.

I was unable to achieve that result with the above sample code.

 

I managed to hide my own public properties by adding the [Browsable(false)] tag to the ones that I don't want to be shown.

Sep 19, 2012 at 1:39 PM
Edited Sep 19, 2012 at 1:53 PM

I agree with Enahs. The example definitely does not work for me as well. Tested and confirmed the SelectedObject binding was correct with a DebugConverter. The example simply does not work...

 

<wpfxpg:PropertyGrid AutoGenerateProperties="False" ShowAdvancedOptions="False" ShowSearchBox="False" ShowSortOptions="False"  SelectedObject="{Binding MyObjectInstance}"> <wpfxpg:PropertyGrid.PropertyDefinitions> <wpfxpg:PropertyDefinition Name="MyName" /> </wpfxpg:PropertyGrid.PropertyDefinitions> </wpfxpg:PropertyGrid>

 

 

 

public class MyObjectClass
{
   public string MyName {get; set;}
}

 

It seems like if the property AutoGenerateProperties doesn't behave this way, then the property is useless. Is there any updated documentation that explains this property, because this example is clearly outdated based on the suggestion of relmaster.

Sep 19, 2012 at 3:44 PM

Found the problem! It appears that the PropertyGrid PropertyDefinitions are constructed on some event fired during presentation. I had my PropertyGrid in a child window which was causing the problem. 

My solution was to RaisePropertyChanged on the SelectedObject binding on the item AFTER displaying my child window. 

Problem solved!

Developer
Oct 2, 2012 at 8:16 PM

markballenger, can you provide more info on that bug please ? Which version of the toolkit are you using ? Are you using a wfxpg:ChildWindow containing a PropertyGrid or a button that when clicked is opening a Window containing a PropertyGrid ? Can you provide more code with the bug ? Thank you.