WPF中所有控制的一种基本样式规则 [英] One basic styling rule for all conrols in WPF

查看:67
本文介绍了WPF中所有控制的一种基本样式规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

I would like to do something like this:

<Style TargetType="Control">
  <Setter Property="VerticalAlignment" Value="Center"></Setter>
</Style>



这可能吗?这样行不通...
我知道我可以为每个控件编写如下内容:



Is this possible? It doesn''t work this way...
I know I could write for every control something like the following:

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource M<ControlBaseStyle}"/>



但是我有10种不同的控件,我真的不想这么做.

有什么想法吗?

谢谢!
Markus



But I have 10 different controls and I don''t really want to do this.

Any ideas?

Thank you!
Markus

推荐答案

您不能执行此操作,但是可以创建一种样式,然后将其用于其他控件.

如果您具有以下样式
You can''t do this, but you can create one style and then use it for other controls.

If you have the following Style
<Style x:Key="ControlBaseStyle" TargetType="{x:Type Control}">
    <Setter Property="Margin" Value="50" />
</Style>



您可以定位所有按钮,例如



You can target all Buttons for instance

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource ControlBaseStyle}"/>



您仍然需要为每种控件类型添加样式,但是您可以进行添加,以使实际样式仅存在一次.



You still need to add the style for each control type, but you can make it so the actual style is only there once.


这篇关于WPF中所有控制的一种基本样式规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆