【发布时间】:2021-05-31 11:43:35
【问题描述】:
我是 oxyplot 的新手,希望将它与带有 xaml 的 C# WPF 一起使用。我的 .xaml 文件有以下代码:
<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>
.xaml.cs 文件如下:
<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>
所以我只是尝试运行上面的简单示例,但在 xaml 文件中收到以下错误消息:
- 未找到类型“oxy:Plot”。确认您没有遗漏程序集参考。
- 命名空间“clr-namespace:CurveMaster”中不存在名称“MainViewModel”。
现在我为 WPF 安装了 oxyplot Nuget 包,安装成功。但是,上面告诉我上述两个问题都是引用问题,但我无法弄清楚问题是什么。安装包后还需要哪些额外的 oxyplot 引用?
其次,为什么它会给我 MainViewModel 不存在消息,而实际上它确实存在于 CurveMaster 命名空间中?
提前致谢。
【问题讨论】:
-
再次检查文档,看来您应该在视图模型上定义一个 PlotModel:oxyplot.readthedocs.io/en/latest/getting-started/hello-wpf.html