2010-02-02 53 views
0

我有一堆Button s在我的應用程序中看起來幾乎相同。它們之間的唯一區別是它們使用的路徑數據。WPF:按鈕,這是一個路徑

這是我對我的應用程序的「最小化按鈕」的作風:

<Style x:Key="MinimizeButton" TargetType="{x:Type Button}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Button}"> 
       <!-- The border is here to make the entire "block" clickable. 
        Without it, only the actual path is clickable. --> 
       <Border Background="Transparent"> 
        <Path Name="ThePath" Data="{StaticResource MinimizeIconPath}" Style="{StaticResource WindowButtonPath}"/> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

正如你所看到的,我基本上只是改變控件模板使用路徑,而不是默認的按鈕東東。但是,這個聲明是只適用於最小化按鈕 –我有幾個其他按鈕,如「最大化」,「恢復」和「關閉」現在處理。問題在於這些按鈕的樣式將是相同的,唯一的區別是其PathData屬性。

你會推薦我做些什麼來使用盡可能少的代碼?

回答