【问题标题】:Override theme brush Windows 10 UWP覆盖主题画笔 Windows 10 UWP
【发布时间】:2015-05-22 08:43:33
【问题描述】:

我正在尝试覆盖 Windows 10 中的一些样式颜色,但无法使其正常工作。

我的 app.xaml 如下所示:

        <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Default" Source="Theme.xaml"/>
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
</Application.Resources>

我的 Theme.xaml 看起来像这样

<ResourceDictionary
x:Key="Default"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<SolidColorBrush x:Key="ListBoxBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxFocusBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxItemPressedBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxItemSelectedForegroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxItemSelectedBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="FocusVisualBlackStrokeThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ScrollBarButtonForegroundThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ScrollBarPanningBackgroundThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ButtonPressedBackgroundThemeBrush" Color="White"/>

<SolidColorBrush x:Key="SearchBoxHitHighlightSelectedForegroundThemeBrush" Color="Red"/>
<SolidColorBrush x:Key="SearchBoxHitHighlightForegroundThemeBrush" Color="Pink"/>

但是它不起作用,它不会在任何地方覆盖样式。

【问题讨论】:

  • “默认”键与深色主题相关,请尝试使用“浅”键添加新行。还要注意 StaticResource 和 ThemeResource 之间的区别。

标签: xaml windows-phone win-universal-app windows-10


【解决方案1】:

您设置的样式适用于 Windows 8 应用。通用 Windows 应用使用的样式已大大简化。

找到它们的最简单方法是将您的 ListBox 添加到页面,在设计器中右键单击它,然后选择 Edit Template... 创建模板的副本并查看使用的名称。

所有控件现在尽可能使用相同的画笔,而不是使用特定控件的画笔。

例如,ListBox 的 Foreground、Background 和 BorderBrush 使用以下画笔:

  • SystemControlForegroundBaseHighBrush
  • SystemControlBackgroundChromeMediumLowBrush
  • SystemControlForegroundBaseHighBrush

【讨论】:

  • 其实我就是这么做的。覆盖的 SearchBox 样式为:pastebin.com/39aG751n 但它无法更改某些颜色,例如 SearchBoxHitHighlightForegroundThemeBrush 和 SearchBoxHitHighlightSelectedForegroundThemeBrush
  • 这在 Windows 10 IoT / UWP 的 RTM 版本中对我有用。例如,要覆盖恼人的粉红色默认重音画笔并将您的品牌颜色放在那里:
【解决方案2】:

为了补充 Rob 的答案,对于那些寻求更广泛的应用范围响应的人,它帮助我找到了完整的默认主题,这些主题可在 \(Program Files)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\&lt;SDK version&gt;\Generic folder 的 Windows SDK 安装,位于 themeresources.xaml 中。

其中是 Default、HighContrast 和 Light 的 ResourceDictionary。默认键处理 UWP 中的 Dark 主题,因为当没有找到默认的“Dark”ResourceDictionary 时将默认使用它。

Default 和 Light 主题有近 1000 种特定于控件的颜色,或者像 Rob 展示的更通用的“SystemControlForeground...”颜色,但在 UWP 中它们主要基于以下 25 种颜色类别:

  • 24 system colors
  • SystemAccentColor,一种操作系统范围的用户定义颜色,UWP 文档在 Design & UI > Style > Color 下有一整页的内容
    • 上面有 6 种较浅和较深的阴影(SystemAccentColorLight1...Dark1 等),但默认资源字典中不使用它们。但是,该颜色的 0.6、0.8 和 .9 不透明度只使用了几次,这是唯一一次使用不透明度。

然后还有来自 Windows 8.1 的 300 多种颜色类别,它们手动选择特定颜色,您可以看到的范围here

唯一的例外是 InkToolBar 样式几乎完全来自高对比度颜色。

高对比度主题从 8 个额外的 System[blank]Colors 中大量提取,类似于 SystemAccentColor,是操作系统范围的值。如果他们选择了高对比度主题,则它们由模板和/或用户定义,这是 Windows 10 在其个性化设置中的一个选项。高对比度也是一个辅助功能,所以我想我会避免覆盖 ResourceDictionary,无论应用品牌如何。

但实际上,通过覆盖 XAML 框架中的 SystemAccentColor 和 24 种 System[blank]Colors,您可以在应用程序中以一致的方式影响数百种特定颜色选择的更改。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多