Jump to: navigation, search

Property Based Content Filters


A collection of property-based content filtering criteria can be applied to child object lists. Some common use cases are as follows.

  • A user can enter a text to reduce the entire child list to a sub list of those whose certain property display values contain that text;
  • A customizer can create UI that presents several text input fields serving as such filters, with each applied to a different property.


For example. One can customize the ChildArea template to include the following.

    <Grid>
      <Border Background="#8000488E" Visibility="{Binding Children.Filters[SomePropertyName], Converter={StaticResource NullObjOrEmptyStrColConverter}}" />
      <Border Background="#90707070" Visibility="{Binding Children.Filters[SomePropertyName], Converter={StaticResource NullObjOrEmptyStrVisConverter}}" />
      <TextBox Text="{Binding Children.Filters[SomePropertyName], Mode=TwoWay, Converter={StaticResource FilterCriterionToValueConverter}}"
               PlaceholderText="SomePropertyName" BorderThickness="0" Foreground="White" Background="Transparent" />
    </Grid>


This is shown as a single text box. The two way binding on Text allows the entered text (case insensitive) to be used as the filter value on property "SomePropertyName" (case sensitive).

When multiple filters are used at the same time, they are combined with "logic and".

For performance/usability reasons, the result list is not immediately refreshed as one types in the text box. Instead, it only happens after the ReloadChildListCommand is triggered.

IC Hint square.pngThe Borders in the example are not mandatory. They serve as indicators of whether a filter is currently applied on the result list. The PlaceHolderText is optional as well.

UpdatePropertyFiltersCommand

The above mentioned two way binding doesn't always work well with all controls and complex bindings. In such cases, the alternative is to use the UpdatePropertyFiltersCommand to supply the filter criteria.

Xamarin

<Grid xmlns:ctrls="clr-namespace:UBIK.CPL.Controls;assembly=UBIK.CPL"
         xmlns:classes="clr-namespace:UBIK.CPL.Classes;assembly=UBIK.CPL">
    <ctrls:PickerExt
       x:Name="Filter"
       ItemsSource="{Binding Properties.AllItems[QUERY].LinkedLevel.Children.Items}"
       ItemDisplayBinding="{Binding Header}"
       SelectionChangedCommand="{Binding Children.UpdatePropertyFiltersCommand}"
       SelectedValuePath="UID"
       SelectedValue="{Binding Children.Filters[STA].Value, Mode=OneWay}">
        <ctrls:PickerExt.SelectionChangedCommandParameter>
            <classes:KeyValueList>
                <classes:KeyValueParameter Key="ClearPropertyFilters" Value="false" />
                <classes:KeyValueParameter Key="STA" Value="{Binding Path=SelectedItem.UID, Source={x:Reference Filter}}" />
            </classes:KeyValueList>
            </ctrls:PickerExt.SelectionChangedCommandParameter>
    </ctrls:PickerExt>
</Grid>

UWP

Not yet available.

The example above uses a UBIK.CPL.Controls.PickerExt control to display a list of query result objects (through the "QUERY" property's LinkedLevel). The UID of the selected object is then passed on as a part of the command parameter and later used as a filter criterion to filter for objects that have their "STA" property value containing the UID string.

  • ClearPropertyFilters: Clear out all existing filters at the current level before executing the command. This is optional and defaults to false;
  • All other parameters: Used as filter criteria where the Keys are the names of the properties by which you want to filter.


By default, the expression used for filtering is Content["PROPERTY_NAME"].DisplayValue.ToLower().Contains(FILTER_VALUE.ToLower())==true. In other words, it checks whether the specified filter value (as string) is contained in the display value of the property. In more advanced scenarios where a different type of comparison is needed, the example (or more specifically the one KeyValueParameter) can be extended into the following, e.g. comparing whether the specified filter value is equal to the value of the property.

<classes:KeyValueParameter Key="STA" Value="{Binding Path=SelectedItem.UID, Source={x:Reference Filter}, Converter={StaticResource FilterValueToCriterion}, ConverterParameter=Content[\&quot;\{0\}\&quot;].Value.ToString().Equals(\&quot;\{1\}\&quot;)\=\=true}" />
IC Hint square.png"&quot;" and "\" are used for escaping the special characters in XAML and C# code respectively. "{0}" and "{1}" are placeholders and get replaced by the property name and the filter value. The end expression being executed in this example is Content["PROPERTY_NAME"].Value.ToString().Equals(FILTER_VALUE)==true