如何定制亚克力刷

时间:2017-07-06 17:35:35

标签: xaml uwp acrylic-material

我想用丙烯酸刷子绘制Stack Panel表面。

<StackPanel Background="{ThemeResource SystemControlAcrylicElementBrush}"></StackPanel>

它对我有用,但是当我想要改变色调和不透明度时会出现问题。有以下代码可以更改它:

<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
    <AcrylicBrush x:Key="MyAcrylicBrush"
        BackgroundSource="HostBackdrop"
        TintColor="#FFFF0000"
        TintOpacity="0.8"
        FallbackColor="#FF7F0000"/>
</ResourceDictionary>

我不知道我应该把它放在哪里并为此重命名画笔?

 <StackPanel Background="{ThemeResource **MyAcrylicBrush**}"></StackPanel>

感谢您的帮助。 附:您需要Windows Insider SDK和系统构建16190或更高版本

2 个答案:

答案 0 :(得分:1)

您可以创建ResourceDictionary,例如名为“ThemeDictionary.xaml”,并将您AcrylicBrush的代码放在那里。

然后在您的App.xaml中,您可以像ResourceDictionary一样引用您的<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="ThemesDictionary.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>

StandardDecoupledTemplateLogicResolver

答案 1 :(得分:0)

方法1:

ResourceDictionary.ThemeDictionaries

中添加Application.Resources

在App.xaml

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Default">
                <AcrylicBrush x:Key="MyAcrylicBrush" BackgroundSource="HostBackdrop" TintColor="#FFFF0000" TintOpacity="0.8" FallbackColor="#FF7F0000"/>
            </ResourceDictionary>

            <ResourceDictionary x:Key="HighContrast">
                <SolidColorBrush x:Key="MyAcrylicBrush" Color="{ThemeResource SystemColorWindowColor}"/>
            </ResourceDictionary>

            <ResourceDictionary x:Key="Light">
                <AcrylicBrush x:Key="MyAcrylicBrush" BackgroundSource="HostBackdrop" TintColor="#FFFF0000" TintOpacity="0.8" FallbackColor="#FFFF7F7F"/>
            </ResourceDictionary>
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
</Application.Resources>

方法2:

正如@ jsmyth886回答

  1. 添加单独的ResourceDictionary文件并放置ResourceDictionary.ThemeDictionaries代码

    <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Default">
            <AcrylicBrush x:Key="MyAcrylicBrush" BackgroundSource="HostBackdrop" TintColor="#FFFF0000" TintOpacity="0.8" FallbackColor="#FF7F0000"/>
        </ResourceDictionary>
    
        <ResourceDictionary x:Key="HighContrast">
            <SolidColorBrush x:Key="MyAcrylicBrush" Color="{ThemeResource SystemColorWindowColor}"/>
        </ResourceDictionary>
    
        <ResourceDictionary x:Key="Light">
            <AcrylicBrush x:Key="MyAcrylicBrush" BackgroundSource="HostBackdrop" TintColor="#FFFF0000" TintOpacity="0.8" FallbackColor="#FFFF7F7F"/>
        </ResourceDictionary>
    </ResourceDictionary.ThemeDictionaries>
    
  2. App.xaml中的MergedDictionaries合并了您的ResourceDictionary文件

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dictionary1.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    
  3. 更多信息: ResourceDictionary and XAML resource referencesXAML for Windows 10 Controls - Styling