2017-03-01 33 views
1

我使用的是第三方ContentControl附帶了以下主題:樣式支持算法FMP中的ControlTemplate資源定義的風格

<Style TargetType="{x:Type xyz:XyzControl}" x:Key="XyzControl"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type xyz:XyzControl}"> 
       <ControlTemplate.Resources> 
        <Style TargetType="Button"> 
        <!-- A lot of styling... --> 
        </Style> 
       </ControlTemplate.Resources> 
       <!-- More template stuff... --> 

我想一些DataTriggers添加此控件按鈕,但我想保持控制主題的默認樣式。

<xyz:XyzControl> 
    <Button> 
    <Button.Style> 
     <Style TargetType="Button" BasedOn="{???}"> 
     <Style.Triggers> 
     </Style.Triggers> 
     </Style> 
    </Button.Style> 
    </Button> 
</xyz:XyzControl> 

我試圖立足於{StaticResource {x:Type Button}}但這加載默認的全局按鈕樣式,而不是在這種情況下的默認樣式。

回答

0

這是不可能的,因爲你不能在另一個ControlTemplate基地ControlTemplate。你將不得不重新定義整個模板作爲一個整體:

WPF: Is there a way to override part of a ControlTemplate without redefining the whole style?

並添加觸發一個Style不會影響或「覆蓋」在控制的ControlTemplate這樣被定義的觸發器你將不得不從頭開始覆蓋整個ControlTemplate

您當然可以將默認的一個複製到您的XAML標記中並根據您的要求進行編輯。

0

添加一鍵第三方的按鈕樣式:

<Style TargetType="Button" x:key="xyzbuttonStyle"> 

則:

<Style TargetType="Button" BasedOn="{StaticResource xyzbuttonStyle}"> 
+0

Thx,但第三方被稱爲第三方,因爲它不是我的聚會:-)我無法更改該代碼。 – hansmaad