如何定制亚克力画笔
How to customize Acrylic brush
我想用亚克力画笔在 Stack Panel 表面上色。
<StackPanel Background="{ThemeResource SystemControlAcrylicElementBrush}"></StackPanel>
它对我有用,但当我想更改 Tint 颜色和不透明度时出现问题。有以下代码可以更改它:
<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>
感谢您的帮助。
P.S。您需要 Windows Insider SDK 和系统版本 16190 或更高版本
您可以创建一个 ResourceDictionary
,例如 "ThemeDictionary.xaml",然后将 AcrylicBrush
的代码放在那里。
然后在您的 App.xaml
中,您可以像这样引用您的 ResourceDictionary
:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ThemesDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
方法一:
在Application.Resources
中添加ResourceDictionary.ThemeDictionaries
在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>
您 MergedDictionaries
在 App.xaml
中合并了您的 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
我想用亚克力画笔在 Stack Panel 表面上色。
<StackPanel Background="{ThemeResource SystemControlAcrylicElementBrush}"></StackPanel>
它对我有用,但当我想更改 Tint 颜色和不透明度时出现问题。有以下代码可以更改它:
<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>
感谢您的帮助。 P.S。您需要 Windows Insider SDK 和系统版本 16190 或更高版本
您可以创建一个 ResourceDictionary
,例如 "ThemeDictionary.xaml",然后将 AcrylicBrush
的代码放在那里。
然后在您的 App.xaml
中,您可以像这样引用您的 ResourceDictionary
:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ThemesDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
方法一:
在Application.Resources
ResourceDictionary.ThemeDictionaries
在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>
您
MergedDictionaries
在App.xaml
中合并了您的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