【问题标题】:Is it possible to create a custom theme brush in a xaml winrt app?是否可以在 xaml winrt 应用程序中创建自定义主题画笔?
【发布时间】:2013-02-01 19:48:45
【问题描述】:

我想在我的应用中创建一个solidbrush 资源,它会根据所选主题改变颜色。

有没有办法做到这一点?

【问题讨论】:

    标签: .net xaml windows-runtime


    【解决方案1】:

    好的,我想通了。在 StandardStyles.xaml 中有一个部分

    您可以在此处为每个不同的主题添加相同的实心画笔元素。

    <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Default">
            <x:String x:Key="BackButtonGlyph">&#xE071;</x:String>
            <x:String x:Key="BackButtonSnappedGlyph">&#xE0BA;</x:String>
            <SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="#CEE3F8"></SolidColorBrush>
            <SolidColorBrush x:Key="ListViewItemPointerOverBackgroundThemeBrush" Color="#E0E0E0"></SolidColorBrush>
            <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBackgroundThemeBrush" Color="#CEE3F8"></SolidColorBrush>
            <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBorderThemeBrush" Color="#CEE3F8"></SolidColorBrush>
            <SolidColorBrush x:Key="HeaderBrush" Color="#FF8AA1B8">
    
            </SolidColorBrush>
        </ResourceDictionary>
        <ResourceDictionary x:Key="Light">
            <SolidColorBrush x:Key="HeaderBrush" Color="#FFCEE3F8">
    
            </SolidColorBrush>
        </ResourceDictionary>
        <ResourceDictionary x:Key="HighContrast">
            <x:String x:Key="BackButtonGlyph">&#xE0A6;</x:String>
            <x:String x:Key="BackButtonSnappedGlyph">&#xE0C4;</x:String>
        </ResourceDictionary>
    </ResourceDictionary.ThemeDictionaries>
    

    在这里,我添加了一个“Light”主题,并在其中 2 个主题中添加了一个名为“HeaderBrush”的实心画笔。

    要实现这个画笔,只需将它作为资源添加到元素中。就这样……

    <AppBar x:Name="BottomAppBar1"   Padding="10,0,10,0" BorderBrush="Blue"  BorderThickness="0 1 0 0" Background="{ThemeResource HeaderBrush}"  AutomationProperties.Name="Bottom App Bar" Opened="BottomAppBar1_Opened" Closed="BottomAppBar1_Closed">
    

    这里我将画笔设置为背景颜色,现在它会随着主题自动改变。

    【讨论】:

    • 我们如何在 UWP 中完成同样的事情?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多