1

我定义了一个控件模板来替换 RadGridView 上过滤控件的默认模板。我正在自动生成列,如何应用此自定义控件模板?

我的网格:

<telerik:RadGridView x:Name="dataGrid" telerik:StyleManager.Theme="Windows8Touch" 
                         AutoGenerateColumns="True"  
                         ColumnWidth="200"
                         ShowInsertRow="true"
                         GroupRenderMode="Flat"
                         ValidatesOnDataErrors="InEditMode"
                         AlternationCount="2" 
                         RowHeight="50"
                         ItemsSource="{Binding Path=TemplateData, Mode=TwoWay}" 
                         ShouldRefresh="{Binding Path=Refresh}" 
                         IsReadOnlyBinding="{Binding IsReadOnly}"
                         CloseProgressWhenRendered="True"
                         ShowGroupPanel="False" CanUserSortColumns="False">

我的模板:

    <ControlTemplate x:Key="FilteringControlTemplate" TargetType="telerik:FilteringControl">
    <Border BorderThickness="{TemplateBinding BorderThickness}"
            Margin="{TemplateBinding Margin}"
            CornerRadius="1"
            BorderBrush="{TemplateBinding BorderBrush}">
        <Border BorderBrush="{StaticResource ControlInnerBorder}" BorderThickness="1" Background="{TemplateBinding Background}">
            <StackPanel MinWidth="200" MaxWidth="350" Margin="{TemplateBinding Padding}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">

                <TextBlock Foreground="Red" FontSize="18">Look, I am different ;)</TextBlock>

                <StackPanel x:Name="PART_DistinctFilter" Visibility="{TemplateBinding DistinctFiltersVisibility}">
                    <CheckBox x:Name="PART_SelectAllCheckBox"
                              IsChecked="{Binding SelectAll, Mode=TwoWay}"
                              Margin="0,2"
                              telerik:LocalizationManager.ResourceKey="GridViewFilterSelectAll"
                              telerik:StyleManager.Theme="{StaticResource Theme}"/>

                    <ListBox x:Name="PART_DistinctValuesList"
                             ItemsSource="{Binding DistinctValues}"
                             telerik:StyleManager.Theme="{StaticResource Theme}"
                             ScrollViewer.HorizontalScrollBarVisibility="Auto"
                             MaxHeight="250"
                             SelectionMode="Multiple">

                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}"
                                          Content="{Binding ConvertedValue}"
                                          VerticalContentAlignment="Center"
                                          telerik:StyleManager.Theme="{StaticResource Theme}"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem"


                                   BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlackTheme, ElementType=ListBoxItem}}"

                                   >
                            </Style>
                        </ListBox.ItemContainerStyle>
                    </ListBox>
                </StackPanel>
                <StackPanel Margin="0,2">
                    <TextBlock telerik:LocalizationManager.ResourceKey="GridViewFilterShowRowsWithValueThat" Margin="0,2,0,0" />
                    <telerik:RadComboBox x:Name="PART_Filter1ComboBox"
                                       Margin="0,2,0,2"
                                       ItemTemplate="{StaticResource ActionTemplate}"
                                       telerik:StyleManager.Theme="{StaticResource Theme}"
                                       ItemsSource="{Binding AvailableActions}"
                                       SelectedItem="{Binding Filter1.Operator, Mode=TwoWay}" />
                    <TextBox x:Name="PART_Filter1TextBox"
                             Text="{Binding Filter1.Value, Mode=TwoWay}"
                             VerticalContentAlignment="Center"
                             Margin="0,2" Padding="3,0"
                             telerik:StyleManager.Theme="{StaticResource Theme}"
                             Height="22" />
                    <CheckBox x:Name="PART_Filter1MatchCaseCheckBox"
                              IsChecked="{Binding Filter1.IsCaseSensitive, Mode=TwoWay}"
                              Visibility="{Binding MatchCaseVisibility}"
                              Margin="0,2"
                              telerik:LocalizationManager.ResourceKey="GridViewFilterMatchCase"
                              telerik:StyleManager.Theme="{StaticResource Theme}"/>
                    <telerik:RadComboBox x:Name="PART_LogicalOperatorsComboBox"
                                       Margin="0,2"
                                       telerik:StyleManager.Theme="{StaticResource Theme}"
                                       ItemTemplate="{StaticResource LogicalOperatorTemplate}"
                                       ItemsSource="{Binding LogicalOperators}"
                                       SelectedItem="{Binding FieldFilterLogicalOperator, Mode=TwoWay}" />
                    <telerik:RadComboBox x:Name="PART_Filter2ComboBox"
                                       Margin="0,2"
                                       telerik:StyleManager.Theme="{StaticResource Theme}"
                                       ItemTemplate="{StaticResource ActionTemplate}"
                                       ItemsSource="{Binding AvailableActions}"
                                       SelectedItem="{Binding Filter2.Operator, Mode=TwoWay}" />
                    <TextBox x:Name="PART_Filter2TextBox"
                             Text="{Binding Filter2.Value, Mode=TwoWay}"
                             VerticalContentAlignment="Center"
                             Margin="0,2" Padding="3,0"
                             telerik:StyleManager.Theme="{StaticResource Theme}"
                             Height="22" />
                    <CheckBox x:Name="PART_Filter2MatchCaseCheckBox"
                              IsChecked="{Binding Filter2.IsCaseSensitive, Mode=TwoWay}"
                              Visibility="{Binding MatchCaseVisibility}"
                              Margin="0,2"
                              telerik:LocalizationManager.ResourceKey="GridViewFilterMatchCase"
                              telerik:StyleManager.Theme="{StaticResource Theme}"/>
                </StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Button x:Name="PART_ApplyFilterButton" Grid.Column="0"
                            Margin="0,2,2,2" Height="22"
                            telerik:LocalizationManager.ResourceKey="GridViewFilter"
                            telerik:StyleManager.Theme="{StaticResource Theme}" />
                    <Button x:Name="PART_ClearFilterButton" Grid.Column="1"
                            Margin="2,2,0,2" Height="22"
                            telerik:LocalizationManager.ResourceKey="GridViewClearFilter"
                            telerik:StyleManager.Theme="{StaticResource Theme}" />
                </Grid>
            </StackPanel>
        </Border>
    </Border>

</ControlTemplate>
4

1 回答 1

2

添加一个样式,它会自动应用模板:

<Style TargetType="telerik:FilteringControl">
        <Setter Property="Template" Value="{StaticResource FilteringControlTemplate}" />
    </Style>

这样,您无需更改可视树中的任何内容。

于 2013-11-01T14:55:11.130 回答