0

我想使用丙烯酸刷子绘制堆栈面板表面。

<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>

感谢帮助。PS 你需要 Windows Insider SDK 和系统版本 16190 或更高版本

4

2 回答 2

1

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

然后在你的App.xaml你可以参考你的ResourceDictionary喜欢:

<Application.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="ThemesDictionary.xaml" />
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Application.Resources>
于 2017-07-06T19:33:53.617 回答
0

方法一:

加入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>

方法二:

正如@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. MergedDictionariesApp.xaml合并你的ResourceDictionary文件

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dictionary1.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    

更多信息: ResourceDictionary 和 XAML 资源引用XAML for Windows 10 控件 - 样式

于 2017-07-07T05:19:33.200 回答