簡體   English   中英

將按鈕的默認樣式應用於CustomButton

[英]Apply default style of Button to a CustomButton

由於某種原因,我做了一個CustomButton:Button。

<Button x:Name="button1"/>
<my:CustomButton x:Name="button2"/>

問題在於button2看起來不像button1,因為默認的Button主題未應用於CustomButton。

我將button1的樣式綁定到button2。

<Button x:Name="button1"/>
<my:CustomButton x:Name="button2" Style="{Binding Style, ElementName=button1}"/>

但這確實不酷。

有什么方法可以將默認的Button樣式應用於CustomButton?

編輯2013/08/10

CustomButton繼承Button。

我的問題是:將button1button2添加到ToolBarbutton2看起來不像button1 ,而是普通的Button。

多謝您的協助!

<Style x:Key="ButtonStyle"  TargetType="BaseTypeOfButtonAndCustomButton">
</Style>
<Style TargetType="Button" BasedOn="{StaticResource ButtonStyle}">
</Style>
<Style TargetType="CustomButton" BasedOn="{StaticResource ButtonStyle}">
</Style>

其中BaseTypeOfButtonAndCustomButton是Button和CustomButton的基類。 為了設置樣式的通用屬性,這是必需的。 然后,您可以基於ButtonStyle構建新的兩種樣式,這些樣式將默認應用於Button和CustomButton。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM