Skip to content

Update the WpfApplication2 example to be compatible with version 2.2.0 #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions getting-started/hello-wpf-xaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataPoint>
{
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<DataPoint> 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
Expand All @@ -76,23 +81,18 @@ Define the namespace in the ``Window`` element, set the ``DataContext`` and add

.. sourcecode:: xml

<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:oxy="http://oxyplot.org/wpf"
xmlns:local="clr-namespace:WpfApplication2"
Title="Example 2 (WPF)" Height="350" Width="525">
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Grid>
<oxy:Plot Title="{Binding Title}">
<oxy:Plot.Series>
<oxy:LineSeries ItemsSource="{Binding Points}"/>
</oxy:Plot.Series>
</oxy:Plot>
</Grid>
</Window>
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:oxy="http://oxyplot.org/wpf"
xmlns:local="clr-namespace:WpfApplication2"
Title="Example 2 (WPF)" Height="350" Width="525">
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Grid>
<oxy:PlotView Model="{Binding Model}"/>
</Grid>
</Window>

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.

Expand Down