
Hello,
I want to hide properties in different categories according to some change outside properry grid. The XAML is as below (the model contains much more properties but for simplicity, I use 3 properties: Name, Description and Gap in 2 categories):
<grids:PropertyGrid x:Name="propertiesGrid" Margin="0" Grid.Row="1" HorizontalContentAlignment="Stretch" IsSummaryVisible="False"
IsFilterActive="True" CanClearDataObjectOnUnload="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="0"
DataObjects="{Binding SelectedItems, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<grids:PropertyGrid.CategoryEditors>
<grids:CategoryEditor Category="Basic information" DisplayName="Basic information" x:Name="basic1">
<grids:CategoryEditor.Properties>
<grids:CategoryEditorProperty PropertyName="Name" />
<grids:CategoryEditorProperty PropertyName="Description" />
</grids:CategoryEditor.Properties>
<grids:CategoryEditor.EditorTemplate>
<DataTemplate>
<Grid Grid.IsSharedSizeScope="True">
<ItemsControl Margin="5" ItemsPanel="{StaticResource FluidMovePanelTemplate}" Width="{Binding ElementName=main, Path=ActualWidth, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
<GridTextBox Label="{Binding Children[Name].Name}" SelectedValue="{Binding Children[Name].Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<GridTextBox Label="{Binding Children[Description].Name}" SelectedValue="{Binding Children[Description].Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</ItemsControl>
</Grid>
</DataTemplate>
</grids:CategoryEditor.EditorTemplate>
</grids:CategoryEditor>
<grids:CategoryEditor Category="Basic information 2" DisplayName="Basic information 2" x:Name="basic2">
<grids:CategoryEditor.Properties>
<grids:CategoryEditorProperty PropertyName="Gap" />
</grids:CategoryEditor.Properties>
<grids:CategoryEditor.EditorTemplate>
<DataTemplate>
<Grid Grid.IsSharedSizeScope="True">
<ItemsControl Margin="5" ItemsPanel="{StaticResource FluidMovePanelTemplate}" Width="{Binding ElementName=main, Path=ActualWidth, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
<GridTextBox Label="{Binding Children[Gap].Name}" SelectedValue="{Binding Children[Gap].Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</ItemsControl>
</Grid>
</DataTemplate>
</grids:CategoryEditor.EditorTemplate>
</grids:CategoryEditor>
</grids:PropertyGrid.CategoryEditors>
<!--<grids:PropertyGrid.DataFactory>
<sample:CustomDataFactory />
</grids:PropertyGrid.DataFactory>-->
<!--<grids:PropertyGrid.ItemContainerStyleSelector>
<grids:PropertyGridItemStyleSelector>
<grids:PropertyGridItemStyleSelector.PropertyStyle>
<Style TargetType="grids:PropertyGridItem">
<Setter Property="Visibility" Value="{Binding IsVisible, Converter={StaticResource BoolToVisibilityConverter}}" />
</Style>
</grids:PropertyGridItemStyleSelector.PropertyStyle>
</grids:PropertyGridItemStyleSelector>
</grids:PropertyGrid.ItemContainerStyleSelector>-->
</grids:PropertyGrid>
My first attempt was to use your sample "PropertyGridDynamicProperties" using CustomDataFactory (commented in XAML) and CustomPropertyModel, but seems it works when not using CategoryEditors as in XAML.
Another attempt was to use a custom filter as below:
private bool CustomFilterPredicate(object model)
{
logger.Info($"=====> {model.GetType()}");
int count = 0;
if (model is ICategoryEditorModel cem)
{
count++;
logger.Info($"=> cem {cem.DisplayName} - {cem.Name}");
}
if (model is ICategoryModel cm)
{
count++;
logger.Info($"=> cm {cm.DisplayName} - {cm.Name}");
}
if (model is IPropertyModel pm/* && pm.Category != "Misc"*/)
{
count++;
logger.Info($"=> pm {pm.DisplayName} - {pm.Name}");
}
if (count == 0)
{
// never hit => no another type
}
return (model is ICategoryEditorModel propertyModel)/* && (propertyModel.DisplayName != propertiesGrid.MiscCategoryName)*/;
}
When I logged that, I realize that the defined properties in the XAML (Name, Description and Gap) never come, but when I remove the stuff for:
<grids:CategoryEditorProperty PropertyName="Description" />
so this property appears in the log. It means I am not able to hide the desired properties.
How can I hide properties when using CategoryEditors?
I like the way using the IsVisible property in your CustomPropertyModel but it did not work on my first attempt.