Is it possible to reference control templates defined in microsoft's assemblies?


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">
                    <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}" />
                                <Thumb x:Name="PART_HeaderGripper" Style="{StaticResource GridViewColumnHeaderGripper}"/>
                            <Trigger Property="IsMouseOver" Value="true">
                            <Trigger Property="IsPressed" Value="true">
                                <Setter TargetName="HeaderContent" Property="Margin" Value="1,1,0,0"/>
                            <Trigger Property="Height" Value="Auto">
                                <Setter Property="MinHeight" Value="20"/>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>

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"
    <Setter Property="Width"
    <Setter Property="Height"
            Value="{Binding Path=ActualHeight,RelativeSource={RelativeSource TemplatedParent}}"/>
    <Setter Property="Padding"
    <Setter Property="Background"
            Value="{StaticResource GridViewColumnHeaderBorderBackground}"/>
    <Setter Property="Template">
            <ControlTemplate TargetType="{x:Type Thumb}">
                <Border Padding="{TemplateBinding Padding}"
                    <Rectangle HorizontalAlignment="Center"
                               Fill="{TemplateBinding Background}"/>

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

5/11/2016 3:36:50 PM

It is possible to reference them, but as paulbetts said, its not recommended as they could change. Also consider if what you are doing is truely 'correct'. Can you edit your question to explain why you need to do this exactly?


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]