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

Only show certain properties

Oct 6, 2013 at 3:16 AM
Hi,

Is there an easy way of only showing the properties that I want? I want the users to be able to edit only certain properties of an object, and preferably not show the other properties.

In the examples, I found a way of not auto generating properties, but that makes you predefine the properties you DO want to show.

I cannot bind to the PropertyDefinitions property, so I cannot dynamically update the Property definitions.

Any help is appreciated!
Oct 6, 2013 at 12:22 PM
After I made this post, I was looking deeper into the code of the propertygrid, and I found out that I could change the behavior of determining what properties to show by implementing the ICustomTypeDescriptor which is called in the ObjectContainerHelper class. This makes me implement way more than just returning the properties. So I dont think this is the right solution.

A different path is to set the ContainerHelper, but I could not find a property to set my own ContainerHelper.

This morning I woke up, and figured that the easiest way of solving my problem, is by making a custom class which inherits the cxeed PropertyGrid, and making a DependencyProperty which changes the selectedObject.
        private void UpdateSelectedObject(object displayed)
        {
            //Get the properties that are decorated with the Editable Attribute
            string[] propertiesToShow = PropertyUtil.GetEditablePropertiesFromObject(displayed);

            //clear the old definitions.
            PropertyDefinitions.Clear();

            //Add the properties to show.
            PropertyDefinitions.Add(new PropertyDefinition() { TargetProperties = propertiesToShow });

            //Set the new selected object
            SelectedObject = displayed;
        }
Although this works, I found out that in wpf I rarely have to inherit controls to change their behavior, bc of attached properties and behaviors. So I am still looking for a different (cleaner/nicer) way of solving this.
Oct 8, 2013 at 6:51 PM
Hi,

Maybe this sample can help ;

Please have a look at the "click Once App" available here : https://wpftoolkit.codeplex.com/
In the sample "Data/PropertyGrid/Using a Custom List", you can set the PropertyGrid.PropertiesSource or PropertyGrid.Properties property to provide your own data to be displayed in the propertyGrid. This allows you to easily insert and removes properties at run time.
This is a feature from the "Plus" version of the toolkit.