Skip to content

Instantly share code, notes, and snippets.

@VisualMelon
Created July 25, 2024 10:17
Show Gist options
  • Save VisualMelon/d23a49b41ad020d8cb73ca8cec4ebd68 to your computer and use it in GitHub Desktop.
Save VisualMelon/d23a49b41ad020d8cb73ca8cec4ebd68 to your computer and use it in GitHub Desktop.
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaApplication1.App"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.Styles>
<FluentTheme />
<!-- Added OxyPlot styles -->
<StyleInclude Source="avares://OxyPlot.Avalonia/Themes/Default.axaml"/>
</Application.Styles>
</Application>
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
namespace AvaloniaApplication1
{
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}
base.OnFrameworkInitializationCompleted();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- This manifest is used on Windows only.
Don't remove it as it might cause problems with window transparency and embedded controls.
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.0.0.0" name="AvaloniaApplication1.Desktop"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
<!-- Added package reference to Avalonia11 version of OxyPlot.Avalonia 2.1.0 (compatible with OxyPlot.Core 2.1.0 and 2.1.2) -->
<PackageReference Include="OxyPlot.Avalonia" Version="2.1.0-Avalonia11" />
</ItemGroup>
</Project>
<!-- Added oxy namespace, and named window Me -->
<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"
xmlns:oxy="using:OxyPlot.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Name="Me"
x:Class="AvaloniaApplication1.MainWindow"
Title="AvaloniaApplication1">
<Grid>
<!-- Added PlotView to present PlotModel -->
<oxy:PlotView Model="{Binding #Me.Plot}" />
</Grid>
</Window>
using Avalonia.Controls;
using OxyPlot;
using OxyPlot.Series;
namespace AvaloniaApplication1
{
public partial class MainWindow : Window
{
// Added PlotModel property to be referenced in XAML
public PlotModel Plot { get; } = new PlotModel() { Title = "Sine" };
public MainWindow()
{
InitializeComponent();
// Added logic to add a series to the plot
Plot.Series.Add(new FunctionSeries(System.Math.Sin, 0, 10, 0.1));
Plot.InvalidatePlot(true);
}
}
}
using Avalonia;
using System;
namespace AvaloniaApplication1
{
internal class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment