2

i have scenario where i have to provide my own control template for a few WPF controls - i.e. GridViewHeader. when you take a look at control template for GridViewHEader in blend, it is agregated from several other controls, which in some cases are styled for that control only - i.e. this splitter between columns. those templates, obviously are resources hidden somewhere in system...dll (or somewhwere in themes dll's). so, my question is - is there a way to reference those predefined templates? so far, i've ended up having my own copies of them in my resources, but i don't like that approach.

here is sample scenario: i have a GridViewColumnHeader:

        <Style TargetType="{x:Type GridViewColumnHeader}" x:Key="gridViewColumnStyle">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
            <Setter Property="Background" Value="{StaticResource GridViewHeaderBackgroundColor}"/>
            <Setter Property="BorderBrush" Value="{StaticResource GridViewHeaderForegroundColor}"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Padding" Value="2,0,2,0"/>
            <Setter Property="Foreground" Value="{StaticResource GridViewHeaderForegroundColor}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                        <Grid SnapsToDevicePixels="true" Tag="Header" Name="Header">
                            <ContentPresenter Name="HeaderContent" Margin="0,0,0,1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            <Canvas>
                                <Thumb x:Name="PART_HeaderGripper" Style="{StaticResource GridViewColumnHeaderGripper}"/>
                            </Canvas>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                            </Trigger>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter TargetName="HeaderContent" Property="Margin" Value="1,1,0,0"/>
                            </Trigger>
                            <Trigger Property="Height" Value="Auto">
                                <Setter Property="MinHeight" Value="20"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

so far - nothing interesting, but say, i want to add some extra functionality straight in the template - i'd leave cotnent presenter as is, add my controls next to it and i'd like to leave Thumb with defaults from framework. i've found themes provided by microsoft here:

the theme for Thumb looks like that:

<Style x:Key="GridViewColumnHeaderGripper"
       TargetType="{x:Type Thumb}">
    <Setter Property="Canvas.Right"
            Value="-9"/>
    <Setter Property="Width"
            Value="18"/>
    <Setter Property="Height"
            Value="{Binding Path=ActualHeight,RelativeSource={RelativeSource TemplatedParent}}"/>
    <Setter Property="Padding"
            Value="0"/>
    <Setter Property="Background"
            Value="{StaticResource GridViewColumnHeaderBorderBackground}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Thumb}">
                <Border Padding="{TemplateBinding Padding}"
                        Background="Transparent">
                    <Rectangle HorizontalAlignment="Center"
                               Width="1"
                               Fill="{TemplateBinding Background}"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

so far - i have to copy & paste that style, while i'd prefer to get reference to it from resources.

4

2 回答 2

2

引用 100% 可能更改的内部资源是不可用的 - 最好只是复制它。

于 2008-09-16T04:39:28.523 回答
0

可以参考它们,但正如 paulbetts 所说,不建议这样做,因为它们可能会改变。还要考虑你所做的是否真的“正确”。你能编辑你的问题来解释为什么你需要这样做吗?

于 2008-09-16T12:31:07.877 回答