Hide Misc category when using CategoryEditors

Grids for WPF Forum

The latest build of this product (v22.1.1) was released 2 months ago, which was before this thread was created.
Posted 1 month ago by Procam
Version: 21.1.1
Avatar

It is possible to hide Misc category by mean of filter:

<grids:PropertyGrid.DataFilter>
    <grids:PropertyModelStringFilter x:Name="stringFilter" Source="Category" Operation="NotEquals" Value="Misc" />
</grids:PropertyGrid.DataFilter>

but when using CategoryEditors like in your Sample app:
SampleBrowser\ProductSamples\GridsSamples\QuickStart\PropertyGridCategoryEditors

and adding in the class AppearanceViewModel a new property:

public string Another { get; set; }

so now the filter is not working, even nothing (no categories) is displayed.

I also tried with a filter predicate:

private bool CustomFilterPredicate(object model)
{
    var propertyModel = model as IPropertyModel;
    return (propertyModel != null) && (propertyModel.Category != propGrid.MiscCategoryName);
}

but it did not help. How can I hide the Misc (or another) category?

Comments (4)

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Thanks for letting us know about this.  We've updated PropertyModelStringFilter for the next maintenance release so that it supports category editors.  After that update, that sample's category editors will show up while the Misc category will not.

In the meantime, you can use a predicate filter.  However note that category editors are type ICategoryEditorModel and not IPropertyModel.  That might be why your predicate filter's results are wrong.


Actipro Software Support

Posted 1 month ago by Procam
Avatar

Thanks for the tip. Works with the filter predicate.

Posted 1 month ago by Procam
Avatar

Maybe another question related to CategoryEditorModel:

I have a PropertyGrid with DataObject = Foo;
the CategoryEditorModel has a collection Children of PropertyDescriptorPropertyModel (the properties of Foo).

Each of this PropertyDescriptorPropertyModel has a property Target that points to the bound object in DataObject (Foo) of the PropertyGrid control. How can I get this Foo object in the level of CategoryEditorModel instead of PropertyDescriptorPropertyModel  ? Has CategoryEditorModel some property to get the bound object?

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Category editors themselves, like categories, don't need to track the target object, so they don't at this time.  If you create a class that inherits TypeDescriptorFactory (and then set an instance of that new class to PropertyGrid.DataFactory), you can override this method:

protected virtual ICategoryEditorModel CreateCategoryEditorModel(CategoryEditor categoryEditor, IDataFactoryRequest request) {
	return new CategoryEditorModel(categoryEditor);
}

The request.DataObjects property should give the target(s) and you could pass that to a custom inherited version of CategoryEditorModel if you wish.

Or alternatively you could make an extension method on ICategoryEditorModel that looks for the first property model in its Children collection and returns its Target.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.