我想用丙烯酸刷子绘制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或更高版本
答案 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)
在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回答
添加单独的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>
App.xaml
中的MergedDictionaries
合并了您的ResourceDictionary
文件
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
更多信息: ResourceDictionary and XAML resource references,XAML for Windows 10 Controls - Styling