Oxyplot Avalonia - 尝试添加 StyleIncludes 时出错

问题描述 投票:0回答:1

我正在创建一个 Avalonia 应用程序,并将使用 Oxyplot。 根据https://github.com/oxyplot/oxyplot-avalonia,使用需要将以下代码添加到app.axaml:

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="Sensei.Presentation.Avalonia.App">
    <Application.Styles>
        <StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
        <StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
      
        <!-- Add the line below to get OxyPlot UI theme applied. -->
        <StyleInclude Source="resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia"/>
      
        <!-- Add the line below to get OxyPlot UI theme applied in Avalonia 11. -->
        <StyleInclude Source="avares://OxyPlot.Avalonia/Themes/Default.axaml"/>
    </Application.Styles>
</Application>

因此,我的文件现在包含以下内容:

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="AdProgrammingGUIAvalonia.App"
             RequestedThemeVariant="Default">
             <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

    <Application.Styles>
        <StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
        <StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
      
        <!-- Add the line below to get OxyPlot UI theme applied. -->
        <StyleInclude Source="resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia"/>
      
        <!-- Add the line below to get OxyPlot UI theme applied in Avalonia 11. -->
        <StyleInclude Source="avares://OxyPlot.Avalonia/Themes/Default.axaml"/>
    </Application.Styles>
</Application>


但是,将其添加到文件后,我收到以下错误:

One or more errors occurred. (Assembly "Avalonia.Themes.Default" was not found from the "avares://Avalonia.Themes.Default/DefaultTheme.xaml" source. Line 8, position 23.) (Assembly "Avalonia.Themes.Default" was not found from the "avares://Avalonia.Themes.Default/Accents/BaseLight.xaml" source. Line 9, position 23.) (Unable to resolve "!AvaloniaResources" type on "OxyPlot.Avalonia" assembly. Line 15, position 23.) (Assembly "Avalonia.Themes.Default" was not found from the "avares://Avalonia.Themes.Default/DefaultTheme.xaml" source. Line 8, position 23.) (Assembly "Avalonia.Themes.Default" was not found from the "avares://Avalonia.Themes.Default/Accents/BaseLight.xaml" source. Line 9, position 23.) (Unable to resolve "!AvaloniaResources" type on "OxyPlot.Avalonia" assembly. Line 15, position 23.)  AdProgrammingGUIAvalonia    D:\Advanced Programming\Advanced-Programming-Project\AdProgrammingGUIAvalonia\App.axaml         

我该如何解决这个问题?我使用的 Avalonia 版本是 11.1.0,我使用的 Oxyplot.Avalonia 版本是 2.1.0-Avalonia11。

c# f# oxyplot avalonia
1个回答
0
投票

我也有同样的问题,但终于找到了出路!

首先,检查你的项目 csproj 文件,确保包设置适合 Avalonia 11。我的如下:

<PackageReference Include="Avalonia" Version="11.2.1" />    
<PackageReference Include="OxyPlot.Core" Version="2.2.0" />
<PackageReference Include="OxyPlot.Avalonia" Version="2.1.0-Avalonia11" />

其次,App.axaml 应设置为:

<Application.Styles>
  <FluentTheme />
  <StyleInclude Source="avares://OxyPlot.Avalonia/Themes/Default.axaml"/>
</Application.Styles>

最后,在您的视图的axaml中添加

xmlns:oxy="http://oxyplot.org/avalonia"
,然后尝试添加

<oxy:Plot Height="150"
         PlotMargins="50 0 0 0"
         PlotAreaBorderColor="#999999">
  <oxy:Plot.Series>
    <oxy:AreaSeries
        DataFieldX="Index"
        DataFieldY="Value"
        Color="#fd6d00" />
  </oxy:Plot.Series>
</oxy:Plot>

用于测试。 任何进一步的事情都可以检查在此 github 问题页面

© www.soinside.com 2019 - 2024. All rights reserved.