Вы можете получить полный образец, который показывает именно то, что вам нужно в демонстрационных файлах, поставляемых с Xceed DataGrid.
Это место по умолчанию на вашем жестком диске будет:
C: \ Xceed Samples \ Xceed DataGrid для WPF Professional Edition v4.2 \ CSharp \ CustomFiltering
Вот фрагмент кода, который показывает, как это сделать, используя AutoFilterControl, который связывается с соответствующим столбцом DataGrid, который вам нужен.
<GroupBox x:Name="groupBox" Header="Auto-filter Actions"
Margin="{StaticResource groupBoxMargin}"
Padding="{StaticResource groupBoxPadding}"
Grid.Column="0">
<StackPanel x:Name="stackPanel">
<!-- ComboBoxes for automatic filtering -->
<Grid Grid.Column="2"
HorizontalAlignment="Right">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="135" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition MinHeight="30" />
<RowDefinition MinHeight="30" />
<RowDefinition MinHeight="30" />
</Grid.RowDefinitions>
<!--ShipCountry combo box-->
<TextBlock Text="Country"
Grid.Column="0"
Grid.Row="0"
Margin="5,2,5,2"
VerticalAlignment="Center" />
<xcdg:AutoFilterControl x:Name="shipCountryAutoFilterControl"
Grid.Column="1"
Grid.Row="0"
AutoFilterColumn="{Binding ElementName=grid, Path=Columns[ShipCountry]}"
AutoFilterContext="{Binding ElementName=grid, Path=(xcdg:DataGridControl.DataGridContext)}"
Focusable="False"
Width="Auto">
<xcdg:AutoFilterControl.Template>
<ControlTemplate TargetType="{x:Type xcdg:AutoFilterControl}">
<ComboBox x:Name="PART_DistinctValuesHost"
Grid.Column="1"
ItemTemplate="{Binding Source={StaticResource countryComboBoxDataTemplate}}"
Initialized="OnShipCountryComboBoxInitialized"
Margin="5,2,5,2" />
</ControlTemplate>
</xcdg:AutoFilterControl.Template>
</xcdg:AutoFilterControl>
<Button x:Name="clearShipCountryButton"
Command="xcdg:AutoFilterControl.ClearAutoFilterValues"
CommandTarget="{Binding ElementName=shipCountryAutoFilterControl}"
Content="Clear"
Grid.Column="2"
Grid.Row="0"
Initialized="OnClearShipCountryButtonInitialized"
Margin="5,2,0,2" />
<!--ShipCity combo box-->
<TextBlock Grid.Column="0"
Grid.Row="1"
Margin="5,2,5,2"
Text="City"
VerticalAlignment="Center" />
<xcdg:AutoFilterControl x:Name="shipCityAutoFilterControl"
Grid.Column="1"
Grid.Row="1"
AutoFilterColumn="{Binding ElementName=grid, Path=Columns[ShipCity]}"
AutoFilterContext="{Binding ElementName=grid, Path=(xcdg:DataGridControl.DataGridContext)}"
Focusable="False"
IsEnabled="{Binding ElementName=shipCountryAutoFilterControl,
Path=AutoFilterContext.AutoFilterValues[ShipCountry].Count,
Converter={StaticResource greaterThanZeroConverter},
ConverterParameter=true}"
Width="Auto">
<xcdg:AutoFilterControl.Template>
<ControlTemplate TargetType="{x:Type xcdg:AutoFilterControl}">
<!-- We only want the City to be selectable when a Country is already selected -->
<ComboBox x:Name="PART_DistinctValuesHost"
Grid.Column="1"
Initialized="OnShipCityComboBoxInitialized"
Margin="5,2,5,2"
SelectionChanged="OnShipCitySelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"
Padding="2,0,0,0" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</ControlTemplate>
</xcdg:AutoFilterControl.Template>
</xcdg:AutoFilterControl>
<Button Command="xcdg:AutoFilterControl.ClearAutoFilterValues"
CommandTarget="{Binding ElementName=shipCityAutoFilterControl}"
Content="Clear"
Grid.Column="2"
Grid.Row="1"
Margin="5,2,0,2" />
<!--OrderDate Month Combo Box-->
<TextBlock Grid.Column="0"
Grid.Row="2"
Text="Month"
Margin="5,2,5,2"
VerticalAlignment="Center" />
<ComboBox ItemsSource="{Binding Source={x:Static globalization:DateTimeFormatInfo.CurrentInfo}, Path=MonthNames}"
Grid.Column="1"
Grid.Row="2"
Initialized="OnOrderMonthComboBoxInitialized"
Margin="5,2,5,2"
SelectionChanged="OnOrderMonthComboBoxSelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"
Padding="2,0,0,0" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button Click="OnClearOrderMonthButtonClick"
Content="Clear"
Grid.Column="2"
Grid.Row="2"
IsEnabled="False"
Initialized="OnClearMonthButtonInitialized"
Margin="5,2,0,2" />
</Grid>
</StackPanel>
</GroupBox>
Это важная часть:
<xcdg:AutoFilterControl x:Name="shipCountryAutoFilterControl"
Grid.Column="1"
Grid.Row="0"
AutoFilterColumn="{Binding ElementName=grid, Path=Columns[ShipCountry]}"
AutoFilterContext="{Binding ElementName=grid, Path=(xcdg:DataGridControl.DataGridContext)}"
Focusable="False"
Width="Auto">