First-Level Inheritanced properties in PropertyGrid

Universal Windows Studio and Shared Library for Universal Windows Forum

Posted 6 years ago by Dylan
Version: 17.2.0322
Avatar

Hi!,

I'm trying your UWP Components and i need have a class that inheritances from another one that inheritances from another one.

I want to be able to control its properties from the PropertyGrid component, but only show the properties of that class and also the ones from its first-parent,

is it possible using reflection and binding flags? if its possible, how?

Thank you!

Comments (9)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Dylan,

Thanks for evaluating PropertyGrid.  While we don't have any specific options for doing that, the nice thing about our product is that you have full control over what property models end up appearing in the PropertyGrid.  

By default there is a TypeReflectionFactory instance set to the PropertyGrid.DataFactory property.  This class is what retrieves all property models, etc.  You could make a class that inherits it and overrides the GetPropertyModels method.  Your override would call the base method to get the property models that show up by default.  Then it could remove the ones that you don't want to show, based on the IPropertyMode.TargetType that they come from.  Then return the resulting trimmed list of property models and that should do the trick.


Actipro Software Support

Posted 6 years ago by Dylan
Avatar

Hi guys,

I tried what you said, however all the properties inside the IList have the same TargetType (ClassA) even when a few of them come from ParentClass


What can i do?

IList<IPropertyModel> trimmedList = base.GetPropertyModels(dataObject, request);

foreach (var item in trimmedList)
{

  if ((item as IPropertyModel).TargetType == typeof(NodeViewModel))
 {

XX.Remove(item);}
}

return trimmedList;

Thanks!

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Dylan,

You're right, the IPropertyModel.TargetType property will return the Type that is being examined and not the source Type of that property (if it was declared on a base class).

The good news is that I believe you can get at the info another way.  The TypeDescriptorFactory.CreatePropertyModel and CreateCollectionPropertyModel methods are called for each property that need to be created.  They pass the source PropertyDescriptor into them.  Override those methods and if you see the propertyDescriptor.ComponentType is not a type that should be included (the request is also passed for context), then return null.  I think that will work for you.


Actipro Software Support

Posted 6 years ago by Dylan
Avatar

Hi guys,

I've tried what you said and it worked, however, i'm getting a few errors:

protected override IPropertyModel CreatePropertyModel(object target, PropertyDescriptor propertyDescriptor, IDataFactoryRequest request)
{

if (propertyDescriptor.ComponentType == typeof(NodeViewModel))
{
return null;
}

return base.CreatePropertyModel(target, propertyDescriptor, request);

}

- An enum property is treated as a string (it should be a combobox)

- If i modify an sttring property the program crash with the following message :

Exception thrown at 0x00007FFEDB4FDE50 (Windows.UI.Xaml.dll) in Program1.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

 

Do you know what could be happening?

 

Thanks

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

UWP doesn't support property descriptors like normal .NET does, we had to mock them up for code compatibility purposes with the WPF version of Grids.  That being said, I don't believe our mockups will trigger standard values for enums like the full .NET framework is capable of doing.  That's why you see a TextBox for Enum props.

If you have also licensed our Editors controls, we do have an EnumEditBox that will get applied to Enum properties when you you set this on your PropertyGrid (see the PropertyGrid Getting Started QuickStart for an example):

gridseditors:BuiltinPropertyEditors.IsEnabled="True"

We haven't seen any access violation exceptions.  Can you repro that in our Getting Started QuickStart if you change the Text property?  That's a string property.


Actipro Software Support

Posted 6 years ago by Dylan
Avatar

The propertyeditors setting worked as expected and now the enum property has a combobox.

I'm trying to debug and see what is happening,

 

The propertygrid is inside a Splitview pane, when i click an element, it sets the dataobject of the propertygrid to that element after that the pane is open and i use the property.

The crash happens when only when i click the textbox of string properties and not if i click the labels.

The crash happens when the propertyeditor loses the focus.

So

Click element, DataObject = element, PaneOpens, Click on label "Name", Click Outside and pane closes , DataObject = null, = WORKS

Click element, DataObject = element, PaneOpens, Click on textbox of "Name", Click Outside and pane closes , DataObject = null = CRASH

It works in the sample browser and i does work for enums or other kind of property.

I cannot debug the session, i only get the following :

Windows.ui.xaml.pdb not loaded

Here you can see the error im getting

https://www.dropbox.com/s/kcrpajfllk8zwaa/error.PNG?dl=0

Thanks

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

So you're saying it doesn't happen in our samples but it does in your app.  Could you make a new simple sample project that shows it happening and email that to our support address?  Please remove the bin/obj folders from the ZIP you send and rename the .zip file extension so it doesn't get spam blocked.  Then we'll have a look at that to see what we can find out. Thanks!


Actipro Software Support

Posted 6 years ago by Dylan
Avatar

Yes, i do not know if its something i did or a bug in the propertygrid component.

i do not know your support email, here you have the project

https://www.dropbox.com/s/7jex82s0gciy5vd/test-pro.rar?dl=0

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Thank you for the sample.  Can you please give us detailed instructions on how to reproduce it with that?

Also, you can find our support address on this page:

https://www.actiprosoftware.com/company/contact


Actipro Software Support

The latest build of this product (v22.1 build 0365) was released 5 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.