首页 > 解决方案 > 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 文件中得到以下错误消息:

  1. 未找到类型“oxy:Plot”。确认您没有丢失程序集引用。
  2. 名称空间“clr-namespace:CurveMaster”中不存在名称“MainViewModel”。

现在我为WPF安装了oxyplot Nuget包,安装成功。但是,上面告诉我上述两个问题都是引用问题,但我无法弄清楚问题是什么。安装软件包后,还需要哪些额外的 oxyplot 引用?

其次,为什么它给我 MainViewModel 不存在消息,而实际上它确实存在于 CurveMaster 命名空间中?

提前致谢。

标签: c#wpfxamloxyplot

解决方案


如果您(或其他人)仍然需要答案 - 这对我有帮助。我还尝试从 Nuget 安装 OxyPlot,它给出了引用和不存在的错误。所以我终于战胜了它:

  1. 我已经从 github 下载了 oxyplot,构建它并手动将必要的 DLL 放入我的解决方案(OxyPlot.dll、OxyPlot.wpf.dll、OxyPlot.wpf.shared.dll)

  2. 我改变了

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

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

在 XAML 中。


推荐阅读