Jump to: navigation, search

Changes


HowTo:Implement Custom Filtering

440 bytes added, 07:58, 19 September 2024
Added a note for INT / dbl type properties, which dont work out of the box
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>
 
=== When One is a Boolean (CheckBox) ===
To process a Boolean filter, the expression needs to be slightly amended, due to the different type of filter match criteria that is required.
 
Note that the below implementation returns all items by default (ie. when the CheckBox is unchecked), and returns only True matches when the CheckBox is checked. This functionality is designed to align with string input, where no filtering occurs for each string until something is entered into the corresponding text input box.
<br>
<source lang = "xml">
Note that this example uses UWP xaml syntax:
 
<controls:EvalExpression x:Name="Bool_FilterExpression" Expression="(INPUT==false) ? &quot;true==true&quot; : EXP" Context="{Binding}">
<controls:EvalExpressionParameter Name="EXP" Value="{Binding ElementName=CheckBox, Path=IsChecked, Converter={StaticResource StringFormatConverter}, ConverterParameter='Item.Values[&quot;MP_BOOL&quot;]==&quot;{0}&quot;'}" />
<controls:EvalExpressionParameter Name="INPUT" Value="{Binding ElementName=CheckBox, Path=IsChecked}" />
</controls:EvalExpression>
</source>
<br>
 
* The individual EvalExpression for a Boolean filter match needs to be amended as follows:
** The INPUT can never be null, as the IsChecked property is either True or False. Therefore we can remove the Null or empty test, and instead, check whether the CheckBox is checked or not. IsChecked=False should 'escape' the expression, and return all items (or, not contribute to the overall filtering).
* The EvalExpressionParameter 'EXP' similarly can be simplified, as it does not need to make a string match with .Contains, but simply check whether the property value matches to True or False.
<br>
Changes only need to be made to the individual EvalExpression. The "FilterExpression" that joins all individual expressions does not need to be amended, other than the regular additional EvalExpressionParameter, and updating the expression accordingly.
 
<br>
 
 
 
 
 
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.
== Other Property Types == === Filtering an INT / Double ===Though the string comparison works mostly the same for a Int / Dbl, you additionally have to include a .ToString() method to the EXP EvalExpressionParameter of that property's individual EvalExpression for it to evaluate:<source lang = "xml">ConverterParameter='Item.Values[&quot;INSTRUCTIONID&quot;].ToString().ToLower().Contains(&quot;{0}&quot;.ToLower())==true'</source><br> === Filtering a Boolean (CheckBox) ===To process a Boolean filter, the expression needs to be slightly amended, due to the different type of filter match criteria that is required. Note that the below implementation returns all items by default (ie. when the CheckBox is unchecked), and returns only True matches when the CheckBox is checked. This functionality is designed to align with string input, where no filtering occurs for each string until something is entered into the corresponding text input box.<br><source lang = "xml">Note that this example uses UWP xaml syntax: <controls:EvalExpression x:Name="Bool_FilterExpression" Expression="(INPUT==false) ? &quot;true==true&quot; : EXP" Context="{Binding}"> <controls:EvalExpressionParameter Name="EXP" Value="{Binding ElementName=CheckBox, Path=IsChecked, Converter={StaticResource StringFormatConverter}, ConverterParameter='Item.Values[&quot;MP_BOOL&quot;]==&quot;{0}&quot;'}" /> <controls:EvalExpressionParameter Name="INPUT" Value="{Binding ElementName=CheckBox, Path=IsChecked}" /></controls:EvalExpression></source><br> * The individual EvalExpression for a Boolean filter match needs to be amended as follows:** The INPUT can never be null, as the IsChecked property is either True or False. Therefore we can remove the Null or empty test, and instead, check whether the CheckBox is checked or not. IsChecked=False should 'escape' the expression, and return all items (or, not contribute to the overall filtering).* The EvalExpressionParameter 'EXP' similarly can be simplified, as it does not need to make a string match with .Contains, but simply check whether the property value matches to True or False.<br>Changes only need to be made to the individual EvalExpression. The "FilterExpression" that joins all individual expressions does not need to be amended, other than the regular additional EvalExpressionParameter, and updating the expression accordingly. <br> === Filtering a GUID Property ===
The expression string seen in the "EXP" command parameters shown above compare a user input with the value stored in Values[MP_PROPERTY], of the requested property. However, in certain cases, it may not be adequate to search in Values[MP_PROPERTY], such as when the property is a GUID. This is because Values[LK_GUID_PROPERTY] returns the UID value of the linked object, whereas Properties.VisibleItems[LK_GUID_PROPERTY].DisplayValue returns the human readable label associated with this linked object.
[[Category:Styling|Custom Filtering]]
[[Category:WinX|Custom Filtering]]
[[Category:Xamarin|Custom Filtering]]
[[Category:XAML|Implement Custom Filtering]]
[[Category:Xamarin|Custom Filtering]]
686
edits