Category visibility change during runtime

Grids for WPF Forum

Posted 4 years ago by Sasha
Version: 14.2.0611
Avatar

Hi, according to this answer  I've rebuilt my propertyGrid. And there is small issue - when properties changing there visibility on runtime, subCategory stays visible, even when all properties became invisible. Is there an example that demonstrates how it is possible to hide subCategory, when there are no visible properties and show when properties become visible?

Thank you.

Comments (4)

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

Hi Sasha,

I looked through the code but unfortunately there doesn't seem to be a way to hide categories dynamically since categories don't have a visibility option.  Properties don't have a built-in visibility either, since the example you are using implements it externally from the product.  I'd probably recommend that you turn off categories in the property grid if you will be potentially hiding all properties in a category.


Actipro Software Support

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

I should have also mentioned in the previous post that if turning off categories isn't an option, you could possibly try to implement visibility for categories in a similar way to how you are doing it for properties, which is based on the code in the Selective Visibility QuickStart.  In the CustomDataFactory class, you could override the CreateCategoryDataAccessor method and then make a CustomCategoryDescriptorDataAccessor.  You'd have to add all the IsVisible sort of logic into that and update MainControl.Resources to add a Trigger for categories that also sets the Visibility.


Actipro Software Support

Posted 4 years ago by Sasha
Avatar

I've overried ICategoryDataAccessor CreateCategoryDataAccessor. So may be I am doing something wrong, but this method is used only when I load Categories, and later, when I change property's visibility, this method is not called. In the code you can see that createCategoryDataAccessor launches when I load properties, and when I change property value and visibility(dataAccessors = base.GetProperties(value, options);) this overriden method is not launching.

      }
            else
            {
                // Fall back to using the base method's results for nested objects
                dataAccessors = base.GetProperties(value, options);
            }

            return dataAccessors;
        }

        protected override ICategoryDataAccessor CreateCategoryDataAccessor(string displayName)
        {
            return new CustomCategoryDescriptorDataAccessor(displayName);
        }

 And my xaml is :

 <Style TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}">
     <Style.Triggers>
         <Trigger Property="DataAccessorType" Value="Category">
             <Setter Property="Visibility" Value="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.IsCategoryVisible, Converter={StaticResource BooleanToVisibilityConverter}}"/>
         </Trigger>
         <Trigger Property="DataAccessorType" Value="Property">
             <Setter Property="Visibility" Value="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.IsVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
         </Trigger>
     </Style.Triggers>
 </Style>

 And secondly property IsCategoryVisible is applaying to all categories, and not to each specific category.

 

Any ideas how to solve this?

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

Hi Sasha,

I wouldn't think that the visibility property would affect all instances if set up properly, since it should be the same sort of mechanism that is used with properties.  I'm not sure how to solve your problem other that perhaps doing a full Refresh of the PropertyGrid to force the category accessors to be recreated.

Another thing you might want to look into is the Filters QuickStarts.  Those enable you to hide properties and the parent categories will be hidden too since this all is part of the PropertyGrid control, versus the machanism you are using which is external.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 8 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.