如何将样式应用于视觉树的某些元素?

时间:2019-07-31 08:32:50

标签: c# wpf avalondock

我正在使用AvalonDock 3,需要将PART_SelectedContentHost [ContentPresenter]保证金值设置为0,0,0,0。

在此元素祖先的generic.xaml模板中,设置如下:

<Style x:Key="AnchorablePaneControlStyle" TargetType="{x:Type avalonDockControls:LayoutAnchorablePaneControl}">
    <Setter Property="TabStripPlacement" Value="Bottom"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type avalonDockControls:LayoutAnchorablePaneControl}">
                <Grid ClipToBounds="true" 
                      SnapsToDevicePixels="true" 
                      KeyboardNavigation.TabNavigation="Local"
                      >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <!--Following border is required to catch mouse events-->
                    <Border Background="Transparent" Grid.RowSpan="2"/>
                    <Border x:Name="ContentPanel" 
                            BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            Background="{TemplateBinding Background}"
                            Grid.Column="0" 
                            KeyboardNavigation.DirectionalNavigation="Contained" 
                            Grid.Row="0" 
                            KeyboardNavigation.TabIndex="2"
                            KeyboardNavigation.TabNavigation="Cycle">
                        <ContentPresenter x:Name="PART_SelectedContentHost"
                                          ContentSource="SelectedContent" 
                                          Margin="{TemplateBinding Padding}"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </Border>
                    <avalonDockControls:AnchorablePaneTabPanel x:Name="HeaderPanel" Margin="2,0,2,2" IsItemsHost="true" Grid.Row="1" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

以某种方式在“动产”资源管理器中,“保证金”属性在本地设置为2、2、2、2。我认为这就是为什么两者都不是的原因

<Style TargetType="{x:Type ContentPresenter}">
    <Setter Property="Margin" Value="0,0,0,0"/>
</Style>

也无法设置新模板。

0 个答案:

没有答案