BrowsableAttributes

Grids for WPF Forum

Posted 8 years ago by Denison Bollay
Version: 10.2.0532
Avatar
I was able to get BrowsableAttributes to work from code with:

List<Attribute> attrs = new List<Attribute>();
attrs.AddRange(SettingsPropertyGrid.BrowsableAttributes);
attrs.Add(new MyAttribute(true));
SettingsPropertyGrid.BrowsableAttributes = attrs;

I would like to use xaml to add attributes the same way as filters, e.g.


<propgrid:PropertyGrid.DataFilter>
<propgrid:PropertyStringFilter x:Name="stringFilter" Operation="Contains" Value="{Binding Path=Text, ElementName=searchText}" StringComparison="CurrentCultureIgnoreCase" />
</propgrid:PropertyGrid.DataFilter>

Can this be done? Can the same effect be achieved by using a new class of filter?

Comments (1)

Posted 8 years ago by Denison Bollay
Avatar
I was successful adding a new subclass of DataFilter:

/// <summary>
/// Filters properties having certain Attribute types in a manner simular to .BrowsableAttributes, but with the extra capabilities of a DataFilter
/// (We use this to limit settings that are for developers and advanced users)
/// </summary>
public class PropertyAttributeFilter : PropertyBooleanFilter
{

/// <summary>
/// Attribute Type to filter out
/// </summary>
public Type AttributeType { get; set; }

/// <summary>
/// This allows inverted control of IsEnabled
/// </summary>
public bool IsDisabled
{
get { return !IsEnabled; }
set { IsEnabled = !value; }
}

/// <summary>
/// Filters out properties having an attribute of type AttributeType (if the filter IsEnabled)
/// </summary>
/// <param name="dataAccessor"></param>
/// <returns>filter = false tells property grid not to filter out this property, e.g. to show the property</returns>
public override bool Filter(IDataAccessor dataAccessor)
{
PropertyDescriptorDataAccessor pdda = dataAccessor as PropertyDescriptorDataAccessor;
CategoryDataAccessor cda = dataAccessor as CategoryDataAccessor;
if (pdda != null)
{
PropertyDescriptor pd = pdda.PropertyDescriptor;
Attribute attr = (Attribute)pd.Attributes[AttributeType];
if (attr != null && attr.GetType() == AttributeType)
return IsEnabled;
else
return false;
}
else if (dataAccessor is CategoryDataAccessor)
return false; //category doesn't matter
else
return base.Filter(dataAccessor);
}
}

So now I can use xaml to combine with other DataFilters:

<propgrid:DataFilterGroup x:Name="groupFilter" Operation="And">
<propgrid:PropertyStringFilter x:Name="stringFilter" Operation="Contains" Value="{Binding Path=Text, ElementName=searchText}" StringComparison="CurrentCultureIgnoreCase" />
<local:PropertyAttributeFilter x:Name="advFilter" AttributeType="local:AdvancedUsersAttribute" />
<local:PropertyAttributeFilter x:Name="devFilter" AttributeType="local:DeveloperAttribute" />
</propgrid:DataFilterGroup>

Works for me! You are welcome to include this in the next release.
The latest build of this product (v2018.1 build 0675) was released 12 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.