基于当前的 WPF 样式 [英] WPF style basedon current

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

问题描述

有没有办法创建一个扩展当前样式的样式,即不是特定样式?

Is there a way to create a style that extends the current style, i.e. not a specific style?

我有一个 WPF 应用程序,我在其中创建样​​式以设置一些属性,例如边框或验证.

I have a WPF application where I create styles to set some properties like borders or validation.

    <Style TargetType="{x:Type Button}"  
           BasedOn="{StaticResource {x:Type Button}}">
        <Setter Property="Padding" Value="5,2,5,2"/>
    </Style>

现在我想尝试一些主题,看看哪一个最适合我的应用程序.问题是要做到这一点,我需要将所有样式上的 BasedOn 属性更改为主题中的样式.

Now I want to try out some Themes to see which one works best for my application. Problem is that to do that I need to change the BasedOn property on all my Styles to the style in the Theme.

    <Style TargetType="{x:Type Button}"  
           BasedOn="="{x:Static ns:SomeTheme.ButtonStyle}">">
        <Setter Property="Padding" Value="5,2,5,2"/>
    </Style>

我可以通过搜索/替换来完成,但如果可以动态完成就好了.

I can do it via search/replace but it would be nice if it could be done dynamicly.

推荐答案

你只需要这样操作,没有捷径可走,你至少要设置BasedOn属性.

You need to do it in this way only, there is no shortcut to do this, you have to set BasedOn attribute atleast.

这篇关于基于当前的 WPF 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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