我有一个用 Avalonia 类库编写的 ContentControl/TemplatedControl,以及在文件中定义的样式。
要在 WPF 中加载样式,您需要使用此 hack 添加 AssemblyInfo.cs
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
现在有了Avalonia......有什么办法呢?
编辑:客户端必须在 App.xaml 中手动注册文件的答案是什么?
<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Default.xaml"/>
</Application.Styles>
但是——如果我想用不同的样式显示多个这样的控件怎么办?我可以在控件上有一个属性来选择主题或颜色。