将按钮的默认样式应用于CustomButton



出于某种原因,我制作了一个CustomButton:Button。

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

问题是按钮2看起来不像按钮1,因为默认的按钮主题未应用于CustomButton。

我正在把纽扣1的款式和纽扣2结合起来。

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

但事实上,这并不酷。

有什么方法可以将默认的按钮样式应用于CustomButton吗?

编辑2013/08/10

CustomButton继承Button。

我的问题是:当我将button1button2添加到ToolBar时,button2看起来不像button1,而是像一个普通的按钮。

谢谢你的帮助!

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

最新更新