Open wwzorz opened 1 year ago
That should work: which OxyPlot.Avalonia package are you targetting and have you tried forcing a restore from the command line with dotnet restore
? (VS certainly used to mess up sometimes in this regard)
This is not a solution, but for version template 0.10.18:
dotnet new install Avalonia.Templates::0.10.18
dotnet new avalonia.app
You can use the Content property. MainWindow.axaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
PlotView plotView = new()
{
Model = _model,
Width = 400,
Height = 300
};
Grid grid = (Grid)Content;
grid.Children.Add(plotView);
}
}
From 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="App1.App">
<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<StyleInclude Source="resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia"/>
</Application.Styles>
</Application>
MainWindow.axaml
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="250"
x:Class="App1.MainWindow"
Title="App1">
<Grid>
</Grid>
</Window>
Not sure what's going on there... the code-behind shouldn't be necessary: I've just installed the same template, created the project, added the nuget reference and defined a PlotView in sample and it 'just works'. Package reference is
<PackageReference Include="OxyPlot.Avalonia" Version="2.1.0" />
The style include is necessary for the plot to appear, but there shouldn't be an error without it.
My complete example code: https://gist.github.com/VisualMelon/26f19b2a9fed7adf41fe121d7925e49e
thank you for reply,this is a version question,use the lower avaliona template can be solved this error!发自我的 iPhone在 2023年9月16日,01:01,VisualMelon @.***> 写道: Not sure what's going on there... the code-behind shouldn't be necessary: I've just installed the same template, created the project, added the nuget reference and defined a PlotView in sample and it 'just works'. Package reference is
The style include is necessary for the plot to appear, but there shouldn't be an error without it. My complete example code: https://gist.github.com/VisualMelon/26f19b2a9fed7adf41fe121d7925e49e
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>
OK. If you are targeting Avalonia 11, you should use the 2.1.0-Avalonia11 nuget version of OxyPlot.Avalonia
thanks,you are right,I am using the latest version and have already resolved this issue using a lower version发自我的 iPhone在 2023年9月16日,01:01,VisualMelon @.***> 写道: Not sure what's going on there... the code-behind shouldn't be necessary: I've just installed the same template, created the project, added the nuget reference and defined a PlotView in sample and it 'just works'. Package reference is
The style include is necessary for the plot to appear, but there shouldn't be an error without it. My complete example code: https://gist.github.com/VisualMelon/26f19b2a9fed7adf41fe121d7925e49e
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>
Because this is the first time I have been exposed to cross platform solutions, the frameworks have been rebuilt and the latest versions have been used. I didn't pay much attention to version issues. Thank you again发自我的 iPhone在 2023年9月17日,22:13,VisualMelon @.***> 写道: OK. If you are targeting Avalonia 11, you should use the 2.1.0-Avalonia11 nuget version of OxyPlot.Avalonia
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>
I am having the same issue. When I try to use oxyPlot I get an erro: Error: Unable to resolve type Plot from namespace using:OxyPlot.Avalonia Line 11, position 10. I tried to include the style as mentioned above with resm or avares but I get an error as well( Error: Unable to resolve XAML resource "avares://AvaloniaApplication1/Designer/OxyPlot.Avalonia.Themes.Default.xaml? assembly=OxyPlot.Avalonia" in the "AvaloniaApplication1" assembly. Make sure this file exists and is public. Line 9, position 23.). I am using the latest version of Avalonia and the .1.0-Avalonia11 nuget version of OxyPlot.Avalonia.
You can find my code here . I am using the latest version of Avalonia with OxyPlot.Avalonia 2.1.0.
The link 404s for me. Double check that a restore has been run: VS can get confused sometimes, and running dotnet restore
manually can resolve that.
Sorry, the repo was not public. You can try again. I tired running dotnet restore but it did not work.
This should be referencing version 2.1.0-Avalonia11
because you are using Avalonia 11 (per https://github.com/LyubomiRadev/PieChart/blob/master/Directory.Build.props#L4 )
So if I understand correctly it should be working, right? So why it isn't :)
The line in the csproj is wrong: it should be
<PackageReference Include="OxyPlot.Avalonia" Version="2.1.0-Avalonia11" />
Thank you. That really helped. But now I can't seem to get it working properly. Nothing is displayed in the window. Can you take a look and tell me what I am doing wrong?
You've commented out the style inclue: https://github.com/LyubomiRadev/PieChart/blob/master/AvaloniaApplication1/App.axaml#L9C8-L9C110
Without the styles, the PlotView
won't have a visual presence.
When I include the Style I get an error: No precompiled XAML found for resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia (baseUri: avares://AvaloniaApplication1/App.axaml), make sure to specify x:Class and include your XAML file as AvaloniaResource. That is why it was commented.
Oh yes, that's the old one. With Avalonia11 you need this style include:
<StyleInclude Source="avares://OxyPlot.Avalonia/Themes/Default.axaml"/>
Fantastic! No building errors whatsoever. But I am not able to display the chart. All I see is the Title of the chart that I've put. I have created the Continents collection as in the example, but I am not able to display the chart. Is the view not detecting the changes in the collection? Also you say that the StyleInclude I was using was the old one. Where can I get the latest updates? I looked in the documentation but I saw information only about WPF, UWP, WinForms etc. but no Avalonia.
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 = this
Then it will match the declared type
https://github.com/LyubomiRadev/PieChart/blob/master/AvaloniaApplication1/Views/MainWindow.axaml#L10
NICE! That work. Thank you for all your help. I am quite new to Avalonia and am not familiar with a lot of things, which is weird, because I worked with WPF for 7 years 😄 Anyway thank you very much :)
build error:
runtime error