wpf将基本样式保留在自定义控件中 [英] wpf keep base style in custom control
本文介绍了wpf将基本样式保留在自定义控件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个自定义按钮,如下所示:
I have created a custom button as I wanted an image and a text inside it as follows:
<Style TargetType="{x:Type Local:ImageButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Local:ImageButton}">
<StackPanel Height="Auto" Orientation="Horizontal">
<Image Margin="0,0,3,0" Source="{TemplateBinding ImageSource}"/>
<TextBlock Text="{TemplateBinding Content}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这里,ImageButton是一个继承自Button类的类,并将ImageSource作为依赖项属性。
Here, ImageButton is a class which inherits from Button class and has ImageSource as a dependency property.
但是我想保留原始按钮的外观。我该怎么办?
But I want to keep the look and feel of the original button. How can I do it?
推荐答案
您可以使用 Style.BasedOn
属性:
You could use the Style.BasedOn
property:
<Style TargetType="{x:Type Local:ImageButton}" BasedOn="{StaticResource {x:Type Button}}">
<!-- ... -->
</Style>
这篇关于wpf将基本样式保留在自定义控件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文