From c9251d867aa4aa1e5e8514439c28f5a2625742c4 Mon Sep 17 00:00:00 2001 From: Joshua Holt Date: Sat, 8 Oct 2022 19:47:48 -0500 Subject: [PATCH 1/2] Porting WPF to Avalonia. --- Netling.Client/App.xaml | 16 ++- Netling.Client/App.xaml.cs | 23 ++++- Netling.Client/LineGraphControl.xaml | 10 +- Netling.Client/LineGraphControl.xaml.cs | 105 ++++++++++---------- Netling.Client/MainWindow.xaml | 41 +++++--- Netling.Client/MainWindow.xaml.cs | 54 ++++++----- Netling.Client/Netling.Client.csproj | 47 ++++++--- Netling.Client/Program.cs | 21 ++++ Netling.Client/ResultWindow.xaml | 18 ++-- Netling.Client/ResultWindow.xaml.cs | 71 ++++++++------ Netling.Client/ValueUserControl.xaml | 36 ++++--- Netling.Client/ValueUserControl.xaml.cs | 123 ++++++++++++------------ 12 files changed, 333 insertions(+), 232 deletions(-) create mode 100644 Netling.Client/Program.cs diff --git a/Netling.Client/App.xaml b/Netling.Client/App.xaml index 3d850f1..c26c844 100644 --- a/Netling.Client/App.xaml +++ b/Netling.Client/App.xaml @@ -1,9 +1,15 @@  + xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + + + + + + + - + @@ -11,4 +17,4 @@ - + \ No newline at end of file diff --git a/Netling.Client/App.xaml.cs b/Netling.Client/App.xaml.cs index 56ed28b..c29caa5 100644 --- a/Netling.Client/App.xaml.cs +++ b/Netling.Client/App.xaml.cs @@ -1,11 +1,24 @@ -using System.Windows; +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; namespace Netling.Client { - /// - /// Interaction logic for App.xaml - /// 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(); + } } -} +} \ No newline at end of file diff --git a/Netling.Client/LineGraphControl.xaml b/Netling.Client/LineGraphControl.xaml index 0ae9ba4..5657df6 100644 --- a/Netling.Client/LineGraphControl.xaml +++ b/Netling.Client/LineGraphControl.xaml @@ -1,12 +1,12 @@ - - + \ No newline at end of file diff --git a/Netling.Client/LineGraphControl.xaml.cs b/Netling.Client/LineGraphControl.xaml.cs index db91cf6..438595b 100644 --- a/Netling.Client/LineGraphControl.xaml.cs +++ b/Netling.Client/LineGraphControl.xaml.cs @@ -2,65 +2,68 @@ using OxyPlot; using OxyPlot.Axes; using OxyPlot.Series; +using Avalonia.Controls; +using Avalonia.Input; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; -namespace Netling.Client +namespace Netling.Client; + +public partial class LineGraphControl : UserControl { - public partial class LineGraphControl + public LineGraphControl() { - public LineGraphControl() - { - InitializeComponent(); - } + InitializeComponent(); + } - public void Draw(IEnumerable points, string trackerFormatString = null) - { - var plotModel = new PlotModel - { - PlotMargins = new OxyThickness(0), - PlotAreaBorderThickness = new OxyThickness(0) - }; + public void Draw(IEnumerable points, string? trackerFormatString = null) + { + var plotModel = new PlotModel + { + PlotMargins = new OxyThickness(0), + PlotAreaBorderThickness = new OxyThickness(0) + }; - plotModel.Axes.Add(new LinearAxis - { - MinimumPadding = 0.01, - MaximumPadding = 0.01, - IsAxisVisible = false, - IsZoomEnabled = false, - IsPanEnabled = false, - Position = AxisPosition.Bottom - }); + plotModel.Axes.Add(new LinearAxis + { + MinimumPadding = 0.01, + MaximumPadding = 0.01, + IsAxisVisible = false, + IsZoomEnabled = false, + IsPanEnabled = false, + Position = AxisPosition.Bottom + }); - plotModel.Axes.Add(new LinearAxis - { - Minimum = 0.0, - MaximumPadding = 0.1, - TickStyle = TickStyle.None, - MajorGridlineStyle = LineStyle.Solid, - MinorGridlineStyle = LineStyle.Dot, - IsZoomEnabled = false, - IsPanEnabled = false, - LabelFormatter = d => "", - AxisTickToLabelDistance = 0 - }); - - var ls = new LineSeries - { - Color = OxyColor.Parse("#ff0079c5"), - CanTrackerInterpolatePoints = false - }; + plotModel.Axes.Add(new LinearAxis + { + Minimum = 0.0, + MaximumPadding = 0.1, + TickStyle = TickStyle.None, + MajorGridlineStyle = LineStyle.Solid, + MinorGridlineStyle = LineStyle.Dot, + IsZoomEnabled = false, + IsPanEnabled = false, + LabelFormatter = d => "", + AxisTickToLabelDistance = 0 + }); - if (trackerFormatString != null) - { - ls.TrackerFormatString = trackerFormatString; - } + var ls = new LineSeries + { + Color = OxyColor.Parse("#ff0079c5"), + CanTrackerInterpolatePoints = false + }; - foreach (var point in points) - { - ls.Points.Add(point); - } + if (trackerFormatString != null) + { + ls.TrackerFormatString = trackerFormatString; + } - plotModel.Series.Add(ls); - Graph.Model = plotModel; + foreach (var point in points) + { + ls.Points.Add(point); } + + plotModel.Series.Add(ls); + Graph.Model = plotModel; } -} +} \ No newline at end of file diff --git a/Netling.Client/MainWindow.xaml b/Netling.Client/MainWindow.xaml index 5204192..24de81f 100644 --- a/Netling.Client/MainWindow.xaml +++ b/Netling.Client/MainWindow.xaml @@ -1,16 +1,28 @@  + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + Title="Netling" Width="500" Height="223"> - - + + + + + + + + + - - + + 10 seconds 20 seconds 1 minute @@ -25,11 +37,16 @@ - - - -