Hide Misc category when using CategoryEditors

Grids for WPF Forum

Posted 2 years 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 2 years 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 2 years ago by Procam
Avatar

Thanks for the tip. Works with the filter predicate.

Posted 2 years 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 2 years 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

The latest build of this product (v24.1.2) was released 14 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.