Changes
Restructuring of page for clarity, plus added content.
This page describes how to customize filtered lists that accept one or multiple user inputs as filter criteria (referred to as 'Dynamic'), alone or combined with predefined criteria(referred to as 'Static'). The custom filtering is following examples are based on four different xaml partsthe Children.Items collection, however, Properties or Documents can be filtered too, by adjusting the ItemsSource in the <cv:ListCollectionView> or <controls:SfDataSourceExt> in UWP or Xamarin respectively. {{Attention|Are you sure you need this?<br>UBIK has a simpler out-of-the-box Property-based filtering technique for filtering child objects when one or multiple property value inputs are the only type of criteria required. See [[Property_Based_Content_Filters]]}} Four elements are required for Custom Filtering:* Input field- for user inputs.* [[EvalExpression]] - for converting user inputs into a filter expression.* List filterCollection Filter - for applying the expression to a collection.* List Items control - for displaying the filtered items.<br>
<br>
<br>
<tabs>
<tab name="UWP">
<source lang = "xml">
</source>
</tab>
<tab name="Xamarin">
<source lang = "xml">
</source>
</tab>
</tabs>
== [[EvalExpression]] = Resources ===With this [[EvalExpression]]For UWP, we can combine it is possible to place the Input text field with the value parameter (property from EvalExpression and Collection Filter into the item we want <Grid.Resources>, as shown below. However, for Xamarin, it is required to filter)use the <ContentView.Resources>.For the Collection Filter, use [[XAML_Changes_in_UBIK_WinX_3.5#Filtering_by_expressions|ListCollectionView]] for UWP & [[Xamarin_XAML#FeatureRelated|Content_filtering]] for Xamarin:
<tabs>
<tab name="UWP">
<source lang = "xml">
<Grid.Resources> <controls:EvalExpression x:Name="FilterExpression" Context="{Binding}" Expression="FC1(INPUT==null||INPUT=="") ? "true" : EXP"> <controls:EvalExpressionParameter Name="FC1INPUT"Value="{Binding ElementName=NameInput, Path=Text}" /> <controls:EvalExpressionParameter Name="EXP" Value="{Binding ElementName=InputTextboxNameNameInput, Path=Text, Converter={StaticResource StringFormatConverter}, ConverterParameter='Item.Values["NAME"].ToLower().Contains("{0}".ToLower())==true'}" /> </controls:EvalExpression> <cv:ListCollectionView x:Key="FilterView" Expression="{Binding ElementName=FilterExpression, Path=Result}" ItemsSource="{Binding Children.Items}" /></Grid.Resources>
</source>
{{Attention|Note that the EvalExpression in UWP requires an x:Name, which in turn requires the 'ElementName' syntax seen in the <cv:ListCollectionView>.}}
{{Attention|Note that the Converter seen in the 'EXP' EvalExpressionParameter in UWP is 'StringFormatConverter', which is different than in Xamarin.}}
</tab>
<tab name="Xamarin">
<source lang = "xml">
<ContentView.Resources> <ResourceDictionary> <controls:EvalExpression x:Key="FilterExpression" Context="{Binding}" Expression="(P1INPUT==null||P1INPUT=="")?"true":P0EXP" Context> <controls:EvalExpressionParameter Name="INPUT" Value="{BindingSource={x:Reference NameInput}, Path=Text}"/> <controls:EvalExpressionParameter Name="P0EXP" Value="{Binding Path=Text, Source={x:Reference Filter_InputNameInput}, Path=Text, Converter={StaticResource FormatterStringFormat}, ConverterParameter='Item.Values["NAME"].ToLower().Contains("{0}".ToLower())==true'}" /> </controls:EvalExpressionParameter NameEvalExpression> <controls:SfDataSourceExt x:Key="P1FilterView" Value Expression="{Binding Path=Text, Source={x:Reference Filter_InputStaticResource FilterExpression}, Path=Result}" ItemsSource="{Binding Children.Items}" /> </controls:EvalExpressionResourceDictionary></ContentView.Resources>
</source>
{{Attention|Note that the EvalExpression in Xamarin requires an x:Key, which in turn requires the 'StaticResource ' syntax seen in the <controls:SfDataSourceExt>.}}
{{Attention|Note that the Converter seen in the 'EXP' EvalExpressionParameter in Xamarin is 'StringFormat', which is different than in UWP.}}
</tab>
</tabs>
<tabs>
<tab name="UWP">
<source lang = "xml">
</source>
</tab>
<tab name="Xamarin">
<source lang = "xml">
</source>
</tab>
</tabs>
==List filter = Items control ===To get An items control will likely be used to this EvalExpression we also need to configure a List filter component like in this case [[XAML_Changes_in_UBIK_WinX_3.5#Filtering_by_expressions|ListCollectionView]] for displaying filtered results, such as <controls:SelectionBoundListView> for UWP & [[Xamarin_XAML#Feature relatedPerformance|Content filteringSfListViewExt]] for Xamarin:
<tabs>
<tab name="UWP">
<source lang = "xml">
<cvcontrols:ListCollectionView SelectionBoundListView x:KeyName="FilterViewFilterQueryList" Expression="{Binding ElementName=FilterExpression, Path=Result}" ItemsSource="{Binding Children.ItemsStaticResource FilterView}" />
</source>
</tab>
<tab name="Xamarin">
<source lang = "xml"><controls:SfDataSourceExt SfListViewExt x:KeyName="FilterViewFilterQueryResultList" Expression ItemsSource="{Binding Path=ResultDisplayItems, Source={StaticResource FilterExpressionFilterView}}" ItemsSource="{Binding Children.Items}" />
</source>
</tab>
</tabs>
<br>
<tabs>
<tab name="UWP">
<source lang = "xml">
</source>
</tab>
<tab name="Xamarin">
<source lang = "xml">
</source>
</tab>
</tabs>
The above example shows how to check for inputs to either property, NAME and DESCR, then use an additional EvalExpression to create the expression string that combines them. For each additional property you need to:* Create an EvalExpression that checks whether the text input is null or empty, and if not, returns the desired expression EXP.* Add each EvalExpression (Name_FilterExpression, Desc_FilterExpression) to the 'main' one (FilterExpression) as Parameters, combined using the escaped '&&' concatenation symbols. {{Attention|Due to the escaped syntax required in the Expression, <source lang ="xml">+"&&"+</source> is the correct syntax required to concatenate filter expressions together.}} Once the additional input controls have been created, processed in their own EvalExpressions, referenced as EvalExpressionParameters and the "FilterExpression" EvalExpression has been adapted as shown, the filter should already function as required; the Collection Filters and Items Controls do not need to be adapted.<br>= List control = Combining Dynamic (User Inputs) and Static (Predefined) Criteria ==The ListView A common use of the Collection Filter is for to filter child lists based on one or multiple properties, such as MetaDefinition.UID or a certain status, to present groups of specific object types. Therefore, it is likely that a customizing may require hardcoded filter criteria, combined with user input, if any is provided. The following describes how to implement such a scenario in XAML, again using/displaying filtered results[[:Category:Multiple Dynamic (User Inputs) Criteria]] as a starting point.
<tabs>
<tab name="UWP">
<source lang = "xml">
<controlsx:String x:Key="Static_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower()=="6f73cde9-ed38-4cbd-8ca1-4597cc2ae621"</x:SelectionBoundListViewString> <controls:EvalExpression x:Name="FilterQueryListFilterExpression" Expression="NAME +"&&"+ DESC +"&&"+ STAT" Context="{Binding}"> ItemsSource <controls:EvalExpressionParameter Name="NAME" Value="{Binding ElementName=Name_FilterExpression, Path=Result}" /> <controls:EvalExpressionParameter Name="DESC" Value="{Binding ElementName=Desc_FilterExpression, Path=Result}" /> <controls:EvalExpressionParameter Name="STAT" Value="{StaticResource FilterViewStatic_FilterExpression}" /></controls:EvalExpression>
</source>
</tab>
<tab name="Xamarin">
<source lang="xml"><controlsx:String x:Key="Static_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower()=="6f73cde9-ed38-4cbd-8ca1-4597cc2ae621"</x:SfListViewExtString> <controls:EvalExpression x:NameKey="FilterQueryResultListFilterExpression"Expression="NAME +"&&"+ DESC +"&&"+ STAT" Context="{Binding}"> ItemsSource <controls:EvalExpressionParameter Name="NAME" Value="{Binding DisplayItemsSource={StaticResource Name_FilterExpression}, Path=Result}" /> <controls:EvalExpressionParameter Name="DESC" Value="{Binding Source={StaticResource FilterViewDesc_FilterExpression}, Path=Result}" /> <controls:EvalExpressionParameter Name="STAT" Value="{StaticResource Static_FilterExpression}" /></controls:EvalExpression>
</source>
</tab>
</tabs>
<tabs>
<tab name="UWP">
<source lang = "xml">
</source>
</tab>
<tab name="Xamarin">
<source lang = "xml">
</source>
</tab>
</tabs>
A good way to inspect and test the target binding is to output it on the items UI, therefore on the ItemTemplate of your ListView, as well as to output the expressions that are being dynamically generated in your EvalExpressions, by binding the Result to the Text property of a <TextBlock> (UWP) or <Label> (Xamarin).
== And / Or Operations ==
All examples of multiple inputs in this article use an 'and' filter condition, where, if any inputs are entered, only items that match all inputs (NAME <b>and</b> DESC) are kept in the collection, to produce a 'filtering down' effect in the user interface.
If a less strict filter condition is required, the FilterExpression can be altered to have an 'or' condition, where all results that match NAME <b>or</b> DESC, but not necessarily both, are shown. To do so, simply change the concatenation syntax to return 'or' symbols (two pipes or '||'):
<source lang = "xml">
+"||;"+
</source>
== See also ==
* [[XAML]]
* [[XAML_Tips]]
* [[Xamarin_XAML]]
[[Category:Client|Custom Filtering]]
[[Category:WinX|Custom Filtering]]
[[Category:Xamarin|Custom Filtering]]
[[Category:Filtering|Custom Filtering]]
[[Category:Styling|Custom Filtering]]