从XCeed DataGrid控件中取出FilterRow

时间:2010-05-27 18:20:58

标签: wpf wpf-controls wpfdatagrid xceed xceed-datagrid

是否可以将 XCeed DataGrid控件 中的过滤器行拉出到其他位置(如组框)?如果可能,怎么样?任何指针都将受到赞赏。

请考虑以下情况,当我点击 过滤器 按钮时, 产品名称 列将被过滤根据过滤查询。为了完成这个场景,我需要为 产品名称 取出FilterRow Cell。

alt text

3 个答案:

答案 0 :(得分:3)

您可以获得一个完整的示例,它可以在Xceed DataGrid附带的演示文件中准确显示您需要的内容。

硬盘上的默认位置是:

External Auto Filter Control C:\ Xceed Samples \ Xceed DataGrid for WPF Professional Edition v4.2 \ CSharp \ CustomFiltering

这是一个代码片段,显示如何使用AutoFilterControl执行此操作,该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">

答案 1 :(得分:0)

是的,这是可能的!查看xceed datagrid文档! http://doc.xceedsoft.com/products/XceedWpfDataGrid/ 很抱歉,我无法找到任何直接链接,因此您必须从左侧面板导航: XCeed DataGrid for WPF-&gt; DataGrid Foundamentals-&gt; Manipulating Data-&gt; Filtering Data

答案 2 :(得分:0)

在DataGridControl定义的XAML中查找FilterRow并删除。

<xcdg:DataGridControl ... > 
  <DataTemplate>
    <xcdg:FilterRow Background="Pink" />
  </DataTemplate>
</xcdg:DataGridControl>