【问题标题】:Oxyplot application - Cannot find referencing error in xaml fileOxyplot 应用程序 - 在 xaml 文件中找不到引用错误
【发布时间】: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 文件中收到以下错误消息:

  1. 未找到类型“oxy:Plot”。确认您没有遗漏程序集参考。
  2. 命名空间“clr-namespace:CurveMaster”中不存在名称“MainViewModel”。

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

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

提前致谢。

【问题讨论】:

标签: c# wpf xaml oxyplot


【解决方案1】:

如果您(或其他人)仍然需要答案 - 这对我有帮助。 我还尝试从 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 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-23
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2020-04-18
    • 1970-01-01
    相关资源
    最近更新 更多