I'm simply trying to plot a Heatmap series using a 2D array of data stored in Cpdata. I've left out the parts not useful to the question. I'm new to wpf and oxyplot and imagine I'm simply making a mistake with bindings somewhere. The xaml code is also below and simplified.
At the moment I am getting a blank window when I run the project. Please let me know if anything is unclear and thanks!
<Window x:Class="Project.Flowfield"
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:Project"
Title="Flowfield" Height="850" Width="1200" MinHeight="700" MinWidth="330"
<Window.DataContext>
<local:OxyPlotModel/>
</Window.DataContext>
<Grid>
<oxy:PlotView x:Name="Cpheatmap" Model="{Binding PlotModel}">
</oxy:PlotView>
</Grid>
using OxyPlot;
using OxyPlot.Series;
using OxyPlot.Axes;
namespace Project
{
public class OxyPlotModel : INotifyPropertyChanged
{
private OxyPlot.PlotModel plotModel; //field
public OxyPlot.PlotModel PlotModel //property
{
get
{
return plotModel;
} //get method
set
{
plotModel = value;
OnPropertyChanged("PlotModel");
} //set method
}
public OxyPlotModel()
{
PlotModel = new PlotModel();
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler!= null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
public partial class Flowfield : Window
{
private OxyPlotModel oxyPlotModel;
public Flowfield()
{
oxyPlotModel = new OxyPlotModel();
DataContext = oxyPlotModel;
InitializeComponent();
}
public double[,] Cpdata = new double[50, 50];
public void RunCommand()
{
//...
//Cpdata is a 2D array calculated from another method (skipped because irrelevant)
//...
var oxyPlotModel = new PlotModel();
var hms = new HeatMapSeries { Data = Cpdata};
oxyPlotModel.Series.Add(hms);
DataContext = this;
}
}
}