Avalonia 中的 Resource.xaml

Aci*_*kie 5 xaml avaloniaui avalonia

我正在使用 avalonia 创建一个应用程序,由于可重用性,它在另一个程序集中有一些 UI 内容。在此附加程序集中,我想要一个由应用程序项目和其他项目引用的 Resource.xml 文件。它包含样式等。

内容:

<ResourceDictionary
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >
    <Style x:Key="normal_button" Selector="Button.normal_button">
        <Setter Property="Margin" Value="0" />
        <Setter Property="Height" Value="25" />
        <Setter Property="MinWidth" Value="75" />
    </Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

错误:

Unable to find suitable setter or adder for property Content of type Avalonia.Styling:Avalonia.Controls.ResourceDictionary for argument Avalonia.Styling:Avalonia.Styling.Style, available setter parameter lists are: ...
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?.csproj 文件中是否需要某些条目?

kek*_*eks 8

无法从资源词典中使用 Avalonia 样式。您需要Styles作为共享文件的根目录并StyleInclude包含在内。

例如 https://github.com/AvaloniaUI/Avalonia/blob/master/samples/ControlCatalog/SideBar.xaml

https://github.com/AvaloniaUI/Avalonia/blob/master/samples/ControlCatalog/App.xaml#L18