WPF使用UIElement设置所有元素的样式

WPF使用UIElement设置所有元素的样式,wpf,styling,uielement,Wpf,Styling,Uielement,以下是我想做的事情: <Application.Resources> <Style TargetType="{x:Type UIElement}"> <Setter Property="Opacity" Value=".1" /> </Style> </Application.Resources> 这样我就可以设计任何类型(而不仅仅是一些最终的具体UI类型)。我不是在

以下是我想做的事情:

<Application.Resources>
    <Style TargetType="{x:Type UIElement}">
        <Setter Property="Opacity"
                Value=".1" />
    </Style>
</Application.Resources>

这样我就可以设计任何类型(而不仅仅是一些最终的具体UI类型)。我不是在寻找最佳实践,而是一个需要思考的问题


我注意到WPF没有为
TargetType
UIElement
FrameworkElement
等)中指定的任何超类设置样式。只有当
TargetType
等同于具体的UI类(
按钮
矩形
)时,它才会设置样式。

如果只想定义基本样式,则可以使用BasedOn属性

<Style TargetType="FrameworkElement" x:Key="ElementBase">
    <Setter Property="Height" Value="24"/>
</Style>

<Style TargetType="TextBlock" BasedOn="{StaticResource ElementBase}">
</Style>

这是一个多一点的工作,但也许它有帮助