Filtering refines the displayed data based on specified conditions.
| XAML |
コードのコピー
|
|---|---|
<Grid x:Name="LayoutRoot"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <c1:C1TextBox x:Name="txtFilter" TextChanged="C1TextBox_TextChanged" Placeholder="Type here to filter" Grid.Row="0" Margin="10 0 0 10" Width="300" HorizontalAlignment="Left"/> <c1:C1ListView x:Name="listView" Grid.Row="1" DisplayMemberPath="Name" Margin="10 0 10 10" /> </Grid> |
|
| C# |
コードのコピー
|
|---|---|
string currentFilterValue; System.Threading.SemaphoreSlim filterSemaphore; public MainWindow() { InitializeComponent(); //Bind to datasource filterSemaphore = new System.Threading.SemaphoreSlim(1); txtFilter.Text = ""; listView.ItemsSource = Person.Generate(100); } // Add grouping by FilterAsync method private async void C1TextBox_TextChanged(object sender, TextChangedEventArgs e) { try { var filter = txtFilter.Text; currentFilterValue = filter; await Task.Delay(400); await filterSemaphore.WaitAsync(); if (currentFilterValue == filter) { await listView.DataCollection.FilterAsync("Name", FilterOperation.Contains, filter); } } finally { filterSemaphore.Release(); } } |
|