oxyplot-avalonia: OxyPlot.Avalonia user error
Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:AvaloniaApplication1.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:AvaloniaApplication1.Views"
xmlns:oxy="using:OxyPlot.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaApplication1.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="AvaloniaApplication1">
<views:MainView>
<TabControl>
<Grid>
<oxy:PlotView></oxy:PlotView>
</Grid>
</TabControl>
</views:MainView>
</Window
build error:
[Error] 16196 UpdateXamlResult error
System.Xaml.XamlException: “Unable to resolve type PlotView from namespace using:OxyPlot.Avalonia Line 16, position 10.”,行号为“16”,行位置为“10”。
runtime error
System.IO.FileNotFoundException:“Could not load file or assembly 'Avalonia.Visuals, Version=0.10.11.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b'. 系统找不到指定的文件。”
请问下为什么会出现编译和运行时错误
About this issue
- Original URL
- State: open
- Created 10 months ago
- Comments: 20 (9 by maintainers)
You’ve commented out the style inclue: https://github.com/LyubomiRadev/PieChart/blob/master/AvaloniaApplication1/App.axaml#L9C8-L9C110 Without the styles, the
PlotViewwon’t have a visual presence.The documentation is pretty patchy, and none of it applies to the Avalonia provision.
You are using compiled bindings, and then using an annoumous type as your data-context: this is asking for trouble. It seems to work fine if you replace it with
this.DataContext = thishttps://github.com/LyubomiRadev/PieChart/blob/master/AvaloniaApplication1/Views/MainWindow.axaml.cs#L40
Then it will match the declared type
https://github.com/LyubomiRadev/PieChart/blob/master/AvaloniaApplication1/Views/MainWindow.axaml#L10
Oh yes, that’s the old one. With Avalonia11 you need this style include:
<StyleInclude Source="avares://OxyPlot.Avalonia/Themes/Default.axaml"/>The line in the csproj is wrong: it should be
<PackageReference Include="OxyPlot.Avalonia" Version="2.1.0-Avalonia11" />https://github.com/LyubomiRadev/PieChart/blob/master/AvaloniaApplication1/AvaloniaApplication1.csproj#L21C5-L21C68
This should be referencing version
2.1.0-Avalonia11because you are using Avalonia 11 (per https://github.com/LyubomiRadev/PieChart/blob/master/Directory.Build.props#L4 )