0

Am new to oxyplot and wish to use it with C# WPF with xaml. My .xaml file has the following code:

<code>
<Window x:Class="CurveMaster.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    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:local="clr-namespace:CurveMaster"
    xmlns:oxy="http://oxyplot.org/wpf"
    mc:Ignorable="d"
    Title="MainWindow" 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>
</code>

The .xaml.cs file is as follows:

<code>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OxyPlot;
namespace CurveMaster
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public class MainViewModel
{
    public MainViewModel()  //Constructor
    {
        this.Title = "My Graph";
        this.Points = new List<DataPoint>
        {
            new DataPoint (0,4),
            new DataPoint (10,13),
            new DataPoint (20,15),
        };
    }
    public string Title { get; private set; }
    public IList <DataPoint> Points { get; private set; }
 }
}

</code>

So I'm just trying to run the above simple example but get the following error messages in the xaml file:

  1. The type 'oxy:Plot' was not found. Verify that you are not missing an assembly reference.
  2. The name "MainViewModel" does not exist in the namespace "clr-namespace:CurveMaster".

Now I installed the oxyplot Nuget package for WPF and installation was successful. However, above tells me that the above two issues are both referencing issues but I cannot figure out what the problem is. What additional oxyplot referencing is required once the package is installed?

Secondly why does it give me the MainViewModel does not exist message when in fact it does exist in the CurveMaster namespace?

Thanks in advance.

Veritas
  • 3
  • 4
  • Check again the documentation, it seems you should define a PlotModel on your view model: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-wpf.html – jalepi May 31 '21 at 22:42

1 Answers1

0

If you (or someone else) still needs the answer - thats what helped me. I also tried to install OxyPlot from Nuget and it gave referencing and non-existing errors. So I finally overpowered it with:

  1. I have downloaded oxyplot from github, built it and took necessary DLL manually into my solution (OxyPlot.dll, OxyPlot.wpf.dll, OxyPlot.wpf.shared.dll)

  2. I have changed

xmlns:oxy="http://oxyplot.codeplex.com"

to

xmlns:oxy="http://oxyplot.org/wpf"

in XAML.

KennetsuR
  • 704
  • 8
  • 17