From 0d5ce62fda399219c90f645e85b435d3adb35b27 Mon Sep 17 00:00:00 2001 From: mingupup <2539823901@qq.com> Date: Mon, 21 Jul 2025 21:50:23 +0800 Subject: [PATCH] Update the WpfApplication2 example to be compatible with version 2.2.0 --- getting-started/hello-wpf-xaml.rst | 78 +++++++++++++++--------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/getting-started/hello-wpf-xaml.rst b/getting-started/hello-wpf-xaml.rst index b514205..2944229 100644 --- a/getting-started/hello-wpf-xaml.rst +++ b/getting-started/hello-wpf-xaml.rst @@ -40,33 +40,38 @@ Then create a class that defines the data to be plotted. .. sourcecode:: csharp - namespace WpfApplication2 - { - using System.Collections.Generic; + namespace WpfApplication2 +{ + using System.Collections.Generic; - using OxyPlot; + using OxyPlot; + using OxyPlot.Series; - public class MainViewModel + public class MainViewModel + { + public MainViewModel() { - public MainViewModel() - { - this.Title = "Example 2"; - this.Points = new List - { - new DataPoint(0, 4), - new DataPoint(10, 13), - new DataPoint(20, 15), - new DataPoint(30, 16), - new DataPoint(40, 12), - new DataPoint(50, 12) - }; - } - - public string Title { get; private set; } - - public IList Points { get; private set; } + // Create the plot model + var model = new PlotModel { Title = "Example 2" }; + + // Create a line series + var series = new LineSeries(); + series.Points.Add(new DataPoint(0, 4)); + series.Points.Add(new DataPoint(10, 13)); + series.Points.Add(new DataPoint(20, 15)); + series.Points.Add(new DataPoint(30, 16)); + series.Points.Add(new DataPoint(40, 12)); + series.Points.Add(new DataPoint(50, 12)); + + // Add the series to the plot model + model.Series.Add(series); + + this.Model = model; } + + public PlotModel Model { get; private set; } } +} Create the view @@ -76,23 +81,18 @@ Define the namespace in the ``Window`` element, set the ``DataContext`` and add .. sourcecode:: xml - - - - - - - - - - - - + + + + + + + + If you want to add a ``Plot`` control in the design view, press ``Choose Items...`` in the Toolbox and browse for the ``OxyPlot.Wpf.dll`` file. If you used NuGet, it should be located in the `packages` folder in your solution folder.