指定模板时ItemContainer样式删除填充

时间:2019-02-12 10:16:05

标签: wpf telerik

我的RadListBox有一个复杂的模板,它是一个Telerik组件。我需要为ItemContainerStyle设置很多触发器,但是我想删除解释的here的填充。如果仅设置ContentPresenter,则该示例可以完美运行,但是对于我来说,这是不够的,因为我拥有Triggers

我的ItemContainerStyle看起来像这样:

<telerik:RadListBox.ItemContainerStyle>
                            <Style TargetType="telerik:RadListBoxItem">
                                <Setter Property="IsEnabled" Value="{Binding IsDisabled, Converter={StaticResource BoolInverseConverter}}"/>

                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="telerik:RadListBoxItem">
                                            <DockPanel>
                                                <Separator x:Name="Separator" DockPanel.Dock="Top" BorderBrush="Gray" BorderThickness="1"/>
                                                <Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="{TemplateBinding Control.Padding}" BorderBrush="{TemplateBinding Border.BorderBrush}"
                                                Background="{TemplateBinding Panel.Background}" Name="Bd" SnapsToDevicePixels="True">

                                                    <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                                              ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" 
                                                              HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                                              VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" 
                                                              SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"/>
                                                </Border>
                                            </DockPanel>
                                            <ControlTemplate.Triggers>
                                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                                                    <Setter Property="Visibility" TargetName="Separator" Value="Collapsed"/>
                                                </DataTrigger>

                                                <Trigger Property="IsSelected" Value="true">
                                                    <Setter TargetName="Bd" Property="Background" Value="#2a579a"/>
                                                    <Setter Property="TextElement.Foreground" TargetName="Bd" Value="White"/>
                                                </Trigger>

                                                <MultiTrigger>
                                                    <MultiTrigger.Conditions>
                                                        <Condition Property="Selector.IsSelectionActive" Value="False"/>
                                                        <Condition Property="Selector.IsSelected" Value="True"/>
                                                    </MultiTrigger.Conditions>
                                                    <Setter Property="Panel.Background" TargetName="Bd"  Value="Black"/>
                                                    <Setter Property="Border.BorderBrush" TargetName="Bd">
                                                        <Setter.Value>
                                                            <SolidColorBrush>#FFDADADA</SolidColorBrush>
                                                        </Setter.Value>
                                                    </Setter>
                                                </MultiTrigger>
                                                <MultiTrigger>
                                                    <MultiTrigger.Conditions>
                                                        <Condition Property="Selector.IsSelectionActive" Value="True"/>
                                                        <Condition Property="Selector.IsSelected" Value="True"/>
                                                    </MultiTrigger.Conditions>
                                                    <Setter Property="Panel.Background" TargetName="Bd" Value="#2a579a"/>
                                                    <Setter Property="TextElement.Foreground" TargetName="Bd" Value="White"/>
                                                    <Setter Property="Border.BorderBrush" TargetName="Bd">
                                                        <Setter.Value>
                                                            <SolidColorBrush>#FF26A0DA</SolidColorBrush>
                                                        </Setter.Value>
                                                    </Setter>
                                                </MultiTrigger>
                                                <Trigger Property="UIElement.IsMouseOver" Value="True">
                                                    <Setter Property="Panel.Background" TargetName="Bd" Value="#2a579a"/>
                                                    <Setter Property="TextElement.Foreground" TargetName="Bd" Value="White"/>
                                                    <Setter Property="Border.BorderBrush" TargetName="Bd">
                                                        <Setter.Value>
                                                            <SolidColorBrush>#A826A0DA</SolidColorBrush>
                                                        </Setter.Value>
                                                    </Setter>
                                                </Trigger>
                                                <Trigger Property="UIElement.IsEnabled" Value="False">
                                                    <Setter Property="TextElement.Foreground" TargetName="Bd" Value="LightGray">
                                                    </Setter>
                                                    <Setter Property="Panel.Background" TargetName="Bd" Value="Transparent"/>
                                                    <Setter Property="TextElement.FontWeight" Value="Normal"/>

                                                </Trigger>
                                                <Trigger Property="UIElement.IsEnabled" Value="True">
                                                    <Setter Property="TextElement.FontWeight" Value="Normal"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </telerik:RadListBox.ItemContainerStyle>

在这种特殊情况下,如何删除ListBox中每个元素的填充?

0 个答案:

没有答案