2008-09-16 51 views
2

我有場景,我必須提供我自己的控制模板的幾個WPF控件 - 即GridViewHeader。當您在混合中查看GridViewHEader的控件模板時,它會從其他幾個控件中聚合,這些控件在某些情況下僅用於該控件的樣式 - 即列之間的分隔符。 這些模板,顯然是隱藏在系統中的某個地方的資源...(或某些主題dll的)。 所以,我的問題是 - 有沒有辦法引用這些預定義的模板?到目前爲止,我已經在我的資源中擁有了自己的副本,但我不喜歡這種方法。是否可以引用在Microsoft組件中定義的控件模板?

這裏是示例場景: 我有一個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> 

迄今爲止 - 沒有什麼有趣的,但是說,我想直接在模板中添加一些額外的功能 - 我要離開cotnent作爲主持人是,添加我的控件旁邊,我想離開拇指從框架的默認值。我已經找到了通過微軟提供的here主題:

爲Thumb主題看起來像這樣:

<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> 

到目前爲止 - 我要複製&粘貼式的,而我更願意得到參考它來自資源。

回答

2

引用內部資源是100%可以改變是不可服務的 - 最好只是複製它。

0

可以引用它們,但正如paulbetts所說,它不推薦,因爲它們可能會改變。還要考慮你所做的是否真的是「正確的」。你能編輯你的問題來解釋你爲什麼需要這麼做嗎?

相關問題