【问题标题】:How to use style explicitly from implicit theme?如何从隐式主题显式使用样式?
【发布时间】:2013-11-11 10:50:22
【问题描述】:

我想使用来自brianlagunas.com 的免费主题中的ToggleButton 样式。

问题是,如果我应用主题,不仅我的切换按钮被设置样式,而且每个控件都根据该主题设置样式。

如何从设计为隐式使用的主题中显式应用样式?

主题是如何加载的

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!-- Light Theme -->
            <ResourceDictionary
             Source="Themes/Metro/Light/Metro.MSControls.Core.Implicit.xaml" />
            <ResourceDictionary
             Source="Themes/Metro/Light/Metro.MSControls.Toolkit.Implicit.xaml" />
            <!-- Dark Theme -->
            <!--
                <ResourceDictionary
                 Source="Themes/Metro/Dark/MetroDark.MSControls.Core.Implicit.xaml" />
                <ResourceDictionary
                 Source="Themes/Metro/Dark/MetroDark.MSControls.Toolkit.Implicit.xaml" />
            -->
        </ResourceDictionary.MergedDictionaries>
        <!-- Light Theme -->
        <SolidColorBrush x:Key="BackgroundKey" Color="#FFFFFF" />
        <!-- Dark Theme -->
        <!--<SolidColorBrush x:Key="BackgroundKey" Color="#FF181818" />-->
    </ResourceDictionary>
</Window.Resources>

我该如何计划使用主题:

<ToggleButton Content="ToggleButton" Width="150"
    Style="{StaticResource ToggleButtonStyle}"/>

谢谢。

【问题讨论】:

  • 我相信你需要为每个主题设置一个x:Key。有了它,您就可以按计划使用它了。
  • @Tico 好的,但我该怎么做呢?我不能使用 resourcedictionary.mergeddictionaries 吗?我应该使用什么?谢谢。
  • 我相信您应该将每个x:Key 放在这样的文件中:Metro.MSControls.Core.Implicit.xaml

标签: c# wpf xaml resourcedictionary


【解决方案1】:

问题是您加载了一个为ToggleButton 定义隐式样式的ResourceDictionary

由于您链接的下载页面实际上是下载完整的解决方案,您有以下选择:

  1. 转到Metro.MSControls.Core.Implicit.xaml 并将切换按钮的样式复制到您的资源(带有ToggleButtonStyle 键的那个,不要忘记“带上”所有必要的画笔)。
  2. 由于那里没有 DLL,我假设您编译了项目/解决方案 - 因此您可以重新编译它。如果是这样,请转到同一文件并注释掉这一行:
<Style BasedOn="{StaticResource ToggleButtonStyle}"
    TargetType="{x:Type ToggleButton}" />

(文件中最后一个样式之前的一个)

重新编译它就可以了。

我肯定会选择选项 2。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    • 2012-01-26
    • 2013-07-13
    • 2012-05-28
    • 1970-01-01
    相关资源
    最近更新 更多