Difference between revisions of "HowTo:Implement Custom Filtering"
(→List control) |
(→Input field) |
||
Line 14: | Line 14: | ||
<tab name="UWP"> | <tab name="UWP"> | ||
<source lang = "xml"> | <source lang = "xml"> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<!-- Textbox for editing --> | <!-- Textbox for editing --> | ||
− | <TextBox x:Name="InputTextboxName | + | <TextBox x:Name="InputTextboxName"> |
− | + | ||
− | + | ||
</TextBox> | </TextBox> | ||
− | |||
</source> | </source> | ||
</tab> | </tab> | ||
Line 37: | Line 22: | ||
<tab name="Xamarin"> | <tab name="Xamarin"> | ||
<source lang = "xml"> | <source lang = "xml"> | ||
− | <Entry x:Name="Filter_Input | + | <Entry x:Name="Filter_Input"> |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</Entry> | </Entry> | ||
</source> | </source> |
Revision as of 08:50, 25 April 2023
The custom filtering is based on four different xaml parts:
- Input field
- EvalExpression
- List filter
- List control
With this Filter, we can filter dynamically without using any evaluate button or something, you just input a value that you want to filter with and it will directly output you any item that contains the filter input.
Input field
The input field is just a basic Textbox/Entry we will use to input the filter criteria value.
It will look like this:
UWP
<TextBox x:Name="InputTextboxName">
</TextBox>
Xamarin
</Entry>
EvalExpression
With this EvalExpression, we can combine the Input text field with the value parameter (property from the item we want to filter).
Here is the final XAML EvalExpression solution:
UWP
Context="{Binding}"
Expression="FC1">
<controls:EvalExpressionParameter Name="FC1"
Value="{Binding ElementName=InputTextboxName, Path=Text, Converter={StaticResource StringFormatConverter}, ConverterParameter='Item.Values["NAME"].ToLower().Contains("{0}".ToLower())==true'}" />
</controls:EvalExpression>
Xamarin
<controls:EvalExpressionParameter Name="P0" Value="{Binding Path=Text, Source={x:Reference Filter_Input}, Converter={StaticResource Formatter}, ConverterParameter='Item.Values["NAME"].ToLower().Contains("{0}".ToLower())==true'}" />
<controls:EvalExpressionParameter Name="P1" Value="{Binding Path=Text, Source={x:Reference Filter_Input}}" />
</controls:EvalExpression>
The best solution would be to place this eval expression into the <Grid.Resources>.
Used namespace:
UWP
Xamarin
List filter
To get used to this EvalExpression we also need to configure a ListCollectionView/Content filtering, that would look like this:
UWP
Expression="{Binding ElementName=FilterExpression, Path=Result}"
ItemsSource="{Binding Children.Items}" />
Xamarin
Expression="{Binding Path=Result, Source={StaticResource FilterExpression}}"
ItemsSource="{Binding Children.Items}" />
Used namespace:
UWP
Xamarin
List control
The ListView is for using/displaying filtered results.
UWP
x:Name="FilterQueryList"
ItemsSource="{StaticResource FilterView}" />
Xamarin
x:Name="FilterQueryResultList"
ItemsSource="{Binding DisplayItems, Source={StaticResource FilterView}}" />
Used namespace:
UWP
Xamarin