c# - Oxyplot 应用程序 - 在 xaml 文件中找不到引用错误
问题描述
我是 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 命名空间中?
提前致谢。
解决方案
如果您(或其他人)仍然需要答案 - 这对我有帮助。我还尝试从 Nuget 安装 OxyPlot,它给出了引用和不存在的错误。所以我终于战胜了它:
我已经从 github 下载了 oxyplot,构建它并手动将必要的 DLL 放入我的解决方案(OxyPlot.dll、OxyPlot.wpf.dll、OxyPlot.wpf.shared.dll)
我改变了
xmlns:oxy="http://oxyplot.codeplex.com"
至
xmlns:oxy="http://oxyplot.org/wpf"
在 XAML 中。
推荐阅读
- spring - 使用 @DataJpaTest 时休眠 @Formula 在 Spring Boot 测试中不起作用
- node.js - Docker - 我可以有两个 FROM 命令吗?
- laravel - Laravel PHPUnit 自动选择默认连接
- node.js - NodeJs:Chrome 检查器可以映射源但无法在原始源上调试
- angular - mat-autocomplete 面板在 Angular 中的表单加载时打开
- javascript - 为什么表格行元素会自动关闭?
- php - Laravel Sanctum 代币 - 两个数据库
- python - 添加产品详细信息后 Django 不显示图像
- spring - springboot mongodb crud update 只改变了字段
- java - 如果 Java 泛型是 NotReifiable,为什么反编译的源(.class 到 .java)仍然有类型信息?