Jump to: navigation, search

Changes


HowTo:Implement Custom Filtering

3,813 bytes added, 3 June
/* Combining Dynamic (User Inputs) and Static (Predefined) Criteria */ Added section on Multiple hardcoded strings
Once one or multiple EvalExpressions have been added to process each input (such as Name_FilterExpression, Desc_FilterExpression), the remaining predefined filter criteria, in this example, filtering for a specific MetaClass by UID, can be added as an x:String, or directly in the EvalExpression paramerter, though the first approach is recommended, for better readability.
<br><br>
{{Attention|The above syntax only works for individual static string filters. If you need to chain multiple hardcoded filters, such as filtering in several UIDs, they need one String resource each, and must be added to the FilterExpression expression individually as in the below example.}}
<br><br>
 
=== Multiple Static Criteria ===
Experimentation has shown that the dynamic filter struggles to combine a single string made of multiple expressions, with additional expressions via the FilterExpression. However, it is still possible to combine user inputs and multiple static criteria, simply by breaking up the static criteria into separate strings.
 
Of course, when for example filtering various MetaDefinitions.UIDs, the '&amp;' (and) comparison condition is no longer appropriate, as there will never be matches for multiple of these UIDs that returns a true result. In these cases, the comparison condition needs to be set to '||' ([[HowTo:Implement_Custom_Filtering#.27Or.27_Operations|Or]]).
The below example shows the correct syntax.
 
<tabs>
<tab name="UWP">
<br>
⛔️ '''Don't Do:'''
<source lang = "xml"><x:String x:Key="Static_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;6f73cde9-ed38-4cbd-8ca1-4597cc2ae621&quot;)==true &amp;&amp; Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;8ca1-4597cc2ae621-6f73cde9-ed38-4cbd&quot;)==true</x:String></source>
<br>
✅ '''Instead Do:'''
<source lang = "xml">
<x:String x:Key="Static1_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;6f73cde9-ed38-4cbd-8ca1-4597cc2ae621&quot;)==true</x:String>
<x:String x:Key="Static2_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;8ca1-4597cc2ae621-6f73cde9-ed38-4cbd&quot;)==true</x:String>
 
<controls:EvalExpression x:Name="FilterExpression" Expression="NAME +&quot;&amp;&amp;&quot;+ STAT1 +&quot;||&quot;+ STAT2" Context="{Binding}">
<controls:EvalExpressionParameter Name="NAME" Value="{Binding ElementName=Name_FilterExpression, Path=Result}" />
<controls:EvalExpressionParameter Name="STAT1" Value="{StaticResource Static1_FilterExpression}" />
<controls:EvalExpressionParameter Name="STAT2" Value="{StaticResource Static2_FilterExpression}" />
</controls:EvalExpression>
</source>
</tab>
 
<tab name="Xamarin"><br>
⛔️ '''Don't Do:'''
<source lang = "xml"><x:String x:Key="Static_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;6f73cde9-ed38-4cbd-8ca1-4597cc2ae621&quot;)==true &amp;&amp; Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;4597cc2ae621-6f73cde9-ed38-4cbd-8ca1&quot;)==true</x:String>
</source>
<br>
✅ '''Instead Do:'''
<source lang = "xml">
<x:String x:Key="Static1_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;6f73cde9-ed38-4cbd-8ca1-4597cc2ae621&quot;)==true</x:String>
<x:String x:Key="Static2_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;4597cc2ae621-6f73cde9-ed38-4cbd-8ca1&quot;)==true</x:String>
 
<controls:EvalExpression x:Key="FilterExpression" Expression="NAME +&quot;&amp;&amp;&quot;+ STAT1 +&quot;||&quot;+ STAT2" Context="{Binding}">
<controls:EvalExpressionParameter Name="NAME" Value="{Binding Source={StaticResource Name_FilterExpression}, Path=Result}" />
<controls:EvalExpressionParameter Name="STAT1" Value="{StaticResource Static1_FilterExpression}" />
<controls:EvalExpressionParameter Name="STAT2" Value="{StaticResource Static2_FilterExpression}" />
</controls:EvalExpression>
</source>
</tab>
</tabs>
{{Hint|Note that the above strings make use of the .Equals() method, which is an alternate option to the more commonly seen 'Item.Content.MetaDefinition.UID.ToString().ToLower()==&quot;...'}}
<br><br>
696
edits