
Hello,
If its not too late, here is a sample for an auto-hidding category that becomes hidden when all its children are hidden:
interface IHideableElement
{
bool IsVisible { get; }
}
class CustomPropertyModel : PropertyDescriptorPropertyModel, IHideableElement
{
private bool? isVisible;
private void InvalidateIsVisible()
{
isVisible = null;
this.NotifyPropertyChanged(nameof(IsVisible));
if (this.Parent is AutoHiddingCategoryModel customCategoryModel)
{
customCategoryModel.InvalidateIsVisible();
}
}
public bool IsVisible
{
get
{
if (!isVisible.HasValue)
{
//Get whether the propertyModel should be visible or not
}
return isVisible.Value;
}
}
}
class AutoHiddingCategoryModel : CategoryModel, IHideableElement
{
private bool? isVisible;
internal void InvalidateIsVisible()
{
isVisible = null;
this.NotifyPropertyChanged(nameof(IsVisible));
if (this.Parent is AutoHiddingCategoryModel customCategoryModel)
{
customCategoryModel.InvalidateIsVisible();
}
}
public bool IsVisible
{
get
{
if (!isVisible.HasValue)
{
isVisible = Children.Any(model => model is IHideableElement iVisibility && iVisibility.IsVisible);
}
return isVisible.Value;
}
}
}
And you can invalidate the visibility of a property when the value changes, for example :
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.PropertyName == nameof(ValueAsString))
{
InvalidateIsVisible();
}
}
[Modified 4 months ago]