在Windows 8.1中创建主题

时间:2014-01-22 15:19:47

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

在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中创建主题?我是否仅限于现有的(浅色和深色)?

1 个答案:

答案 0 :(得分:3)

是的,你被限制在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>