我无法让 Oxyplot Heatmap 在我的 WPF 项目中工作。任何想法我做错了什么?

I'm having trouble getting Oxyplot Heatmap to work in my WPF project. Any ideas what I'm doing wrong?

我只是想使用存储在 Cpdata 中的二维数据数组绘制热图系列。我省略了对问题没有用的部分。我是 wpf 和 oxyplot 的新手,我想我只是在某处的绑定上犯了一个错误。 xaml 代码也在下方并进行了简化。

目前,当我 运行 项目时,window 一片空白。 如果有任何不清楚的地方,请告诉我,谢谢!

<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;
        }
    }
}

RunCommand() 中,您将 window(流场)的数据上下文重置为其自身。 DataContext 需要是 OxyPlotModel,因为您的 PlotView 绑定到它的 PlotModel 属性。

另外,考虑到您说您删除了一些代码,您甚至不需要在命令中创建一个新的 OxyPlotModel 实例。只需在现有实例中设置相关属性或 clear/add 系列,由于它会在其 属性 setter 中引发更改通知,因此绑定将更新。