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

Hiding required properties present in the Base class

Jul 3, 2012 at 9:32 AM

Hi,

I am using the WPF Extended PropertyGrid. presently all the properties of the base class which have been marked with browsable attribute are displayed in the property grid by default. I am having a scenario where in i need to hide some of the properties of the base class based on the derived class type. How can  i acheive this? Please let me know.

Best Regards,

Ram

Coordinator
Jul 3, 2012 at 4:28 PM
Edited Jul 3, 2012 at 4:28 PM

Hi,

 

One thing you could do is to specify explicitly the properties you want to expose.  If you look at the documentation, you'll see that you may disable auto generated properties and specify explicitly the properties you want to show. 

<xctk:PropertyGrid AutoGenerateProperties="False">
   <!-- Only the following properties will be displayed in the PropertyGrid -->
   <xctk:PropertyGrid.PropertyDefinitions>
      <xctk:PropertyDefinition Name="FirstName" />
      <xctk:PropertyDefinition Name="FavoriteColor" />
      <xctk:PropertyDefinition Name="PetNames" />
   </xctk:PropertyGrid.PropertyDefinitions>
</xctk:PropertyGrid>

 

 Since you'll want to add or remove properties based on the inspected object's type, you'll probably need to do this in code-behind.  Unfortunately, because of the bug #18301, the changes done in the PropertyGrid.PropertyDefinitions will not be reflected automatically.  You may work around this issue by resetting the PropertyGrid.SelectedObject.

var selectedObject = _propertyGrid.SelectedObject;
_propertyGrid.SelectedObject = null;
_propertyGrid.SelectedObject = selectedObject;

 

Jul 11, 2012 at 7:53 AM
    public interface IPlacement : ICloneable, IEquatable<IPlacement>
    {       
        double Height { get; set; }       
        double Width { get; set; }       
        double XCoord { get; set; }      
        double YCoord { get; set; }
     }
     
     
     public abstract class UIControl
     {
     	//....has many other properties
     	
	public IPlacement Placement
	{
	    get;
	    set;
	}
	
	//..has many other properties
     }
     
     public class MyEditControl : UIControl
     {
     	//This class has some properties
     }
     
     public class MyControl : UIControl
     {
     	//This is my Custom Control which contains a property of type "MyEditControl"
     }

I have many other classes which look similar to "MyControl" in design which have many other properties specific to each of them.So now

when i set the PropertyGrid.SelectedObject value at runtime, i want "Placement" to be displayed for "MyControl" type and "Placement"

to be hidden for "MyEditControl" type. I want to display all the properties but just hide only 1 property.

It will be huge code to add all the propertydefinitions in codebehind just to hide one property in my case. Is there any other

workaround for this Issue. Please let me know.

 

Thanks,

Ram

Jul 19, 2012 at 9:17 PM

Hello Ram,

We had the same issue a while ago and implemented an ExcludedProperties collection that worked just like PropertyDefinitions except in reverse. If you send me an email at j2associates    at yahoo dot com, I'll try to send you the code.

Aug 17, 2012 at 10:01 PM
Edited Aug 17, 2012 at 10:01 PM

Probably just adding the "Browsable" attribute to false on your property will do the job.

[Browsable(false)]

Oct 1, 2012 at 4:16 PM
Nebuleux wrote:

Hi,

 

One thing you could do is to specify explicitly the properties you want to expose.  If you look at the documentation, you'll see that you may disable auto generated properties and specify explicitly the properties you want to show. 

<xctk:PropertyGrid AutoGenerateProperties="False">
   <!-- Only the following properties will be displayed in the PropertyGrid -->
   <xctk:PropertyGrid.PropertyDefinitions>
      <xctk:PropertyDefinition Name="FirstName" />
      <xctk:PropertyDefinition Name="FavoriteColor" />
      <xctk:PropertyDefinition Name="PetNames" />
   </xctk:PropertyGrid.PropertyDefinitions>
</xctk:PropertyGrid>

 

 Since you'll want to add or remove properties based on the inspected object's type, you'll probably need to do this in code-behind.  Unfortunately, because of the bug #18301, the changes done in the PropertyGrid.PropertyDefinitions will not be reflected automatically.  You may work around this issue by resetting the PropertyGrid.SelectedObject.

var selectedObject = _propertyGrid.SelectedObject;
_propertyGrid.SelectedObject = null;
_propertyGrid.SelectedObject = selectedObject;

 

The Issue 18301 has been fixed. This workaround is no longer needed.