【问题标题】:Create a theme in Windows 8.1在 Windows 8.1 中创建主题
【发布时间】:2014-01-22 15:19:46
【问题描述】:

在 Windows 8 中,您可以为自己的应用程序创建自己的主题 (here's a tutorial)。

在 Windows 8.1 应用程序中,主题的处理方式不同:您可以在运行时更改主题并为 XAML 中的特定控件设置主题(如果您不想将主题应用于整个应用程序)。

例如:

<Grid x:Name="MainGrid" RequestedTheme="Dark">

但是,我找不到创建自己的主题的方法。属性RequestedTheme 采用枚举(其类型为FrameworkElement.RequestedTheme),并且不能扩展定义的枚举(在C# 中)。另外,如果我想定义一个新的Theme Dictionary,我会写:

<ResourceDictionary.ThemeDictionaries>

但它在 Windows 8.1 中不可用。

如何在 Windows 8.1 中创建主题?我是否仅限于现有的(浅色和深色)?

【问题讨论】:

  • 您不会创建新主题,而是覆盖 3 个现有主题。

标签: xaml windows-runtime winrt-xaml windows-8.1


【解决方案1】:

是的,我相信你仅限于 3 个主题

默认(浅色) 黑暗的 高对比度

您可以在 8.1 中为这 3 个主题创建新样式或覆盖现有样式

 <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Default">
                <Style TargetType="TextBlock">
                    <Setter Property="FontSize" Value="24" />
                    <Setter Property="Foreground" Value="Green"/>
                </Style>
            </ResourceDictionary>
            <ResourceDictionary x:Key="Dark">
                <Style TargetType="TextBlock">
                    <Setter Property="FontSize" Value="30" />
                    <Setter Property="Foreground" Value="Orange"/>
                </Style>
            </ResourceDictionary>
            <ResourceDictionary x:Key="HighContrast">
                <Style TargetType="TextBlock">
                    <Setter Property="FontSize" Value="24" />
                    <Setter Property="Foreground" Value="Blue"/>
                </Style>
            </ResourceDictionary>               
        </ResourceDictionary.ThemeDictionaries>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多