Using FluentAvalonia styles for Avalonia in .NET.
Let's say I want to edit the default style to set the button background to AccentColor3 and on hover AccentColor2. How do I do that?
First, setting this style works; but setting ThemeAccentBrush3
doesn't. How do I set set the accent in a way that works for both dark and light themes?
<Style Selector="Button">
<Setter Property="Background" Value="{DynamicResource SystemAccentColorDark3}" />
</Style>
Second, I figured that the best approach is to create an Avalonia Dictionary file
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StaticResource x:Key="ButtonBackground" ResourceKey="SystemAccentColorDark3" />
<StaticResource x:Key="ButtonBackgroundPointerOver" ResourceKey="SystemAccentColorDark2" />
</ResourceDictionary>
And then reference in App.axaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source='avares://Common.Avalonia.App/Styles/DarkResources.axaml'/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
However, styles are loaded further down, and thus don't exist yet.
<Application.Styles>
<sty:FluentAvaloniaTheme />
Thus...
Static resource 'SystemAccentColorDark3' not found.
What's the cleanest solution?
2条答案
按热度按时间mzaanser1#
应该对你的背景值起作用,那么:
对于您的
mouseover
,控件有一种使用pseudoclasses
表示的“状态”,在运行时应用,您可以在样式中将其作为目标,在本例中为Button:pointerover
。pxq42qpu2#
通过将“accent”样式转换为不同的语法来覆盖资源,我成功地获得了默认样式为.35不透明度的“accent”样式......要完成此转换需要相当复杂的引用,但它很有效。
需要在应用程序.xaml中的FluentAvalonia之后插入词典
此外,要查看可用资源的列表,我可以运行FluentAvalonia示例应用程序,该应用程序有一个页面,允许可视化资源和颜色的整个列表。
作为绑定适应主题的说明:StaticResource只运行一次,DynamicResource跟踪更改。要覆盖资源键,需要
StaticResource
。