C# WPF OxyPlot错误:在命名空间中找不到绘图。

3

您好,我在配置WPF中的oxyplot时遇到了问题。我找到了一些解决方案,但都没有奏效。我发现这是最好的http://blog.bartdemeyer.be/2013/03/creating-graphs-in-wpf-using-oxyplot/,但仍然有问题,在XAML文件中出现以下错误:

名称空间codeplex中不存在名为plot的内容。

MainWindow.xaml文件:

<Window x:Class="OxyPlotDemo.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:OxyPlotDemo"
     xmlns:oxy="http://oxyplot.codeplex.com"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">

<Grid>
    <oxy:Plot x:Name="Plot1" Title="A Graph" Model="{Binding PlotModel}" Margin="10" Grid.Row="1">
    </oxy:Plot>
</Grid>

MainWindow.xaml.cs

using System.Windows;
namespace OxyPlotDemo

{

public partial class MainWindow : Window
{

    private ViewModels.MainWindowModel viewModel;
    public MainWindow()
    {

        viewModel = new ViewModels.MainWindowModel();
        DataContext = viewModel;

        InitializeComponent();
    }
}
}

MainWindowModel.cs

using  System.ComponentModel;
using OxyPlot;


namespace OxyPlotDemo.ViewModels
{
    public class MainWindowModel : INotifyPropertyChanged
    {
        private PlotModel plotModel;
        public PlotModel PlotModel
        {
            get { return plotModel; }
            set { plotModel = value; OnPropertyChanged("PlotModel"); }
    }

    public MainWindowModel()
    {
        PlotModel = new PlotModel();
    }

    public event PropertyChangedEventHandler PropertyChanged;

    //[NotifyPropertyChangedInvocator]
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }
}
}

也许有更好的解决方案。我只需要显示一些包含传感器大量数据的图表,不需要实时展示。


2
请尝试使用 xmlns:oxy="http://oxyplot.org/wpf" - Jose
@Kirenenko 我试过了,当我这样做时,在XAML中也会出现这个错误,但是它写着:"Mode"成员无法识别或者无法访问。 - user1974549
也许你在代码的某个地方写成了"Mode"而不是"Model"? - Jose
1
使用<oxy:PlotView>代替<oxy:Plot> - Jose
这是一个来自官方页面的基础教程http://docs.oxyplot.org/en/latest/getting-started/hello-wpf.html#create-project。只需将PlotModel绑定到PlotView Model属性,并在ViewModel上编辑您想要的所有属性。 - Jose
显示剩余3条评论
3个回答

3
我曾经遇到过与NuGet中的OxyPlot库相关的问题,当我从1.x版本迁移到2.1版本时。我发现,在2.1版本中,Plot类已被移动到另一个库中,请查看他们在GitHub页面上的发行历史。这对我有用:

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

xmlns:oxycontrols="http://oxyplot.org/wpf/contrib"

<oxycontrols:Plot .../>


2
<Window x:Class="Universal_trc_csvParser.Window1"
        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:Universal_trc_csvParser"
        xmlns:oxy="http://oxyplot.org/wpf"
        mc:Ignorable="d"
        Title="Window1" Height="450" Width="800">

    <Window.DataContext>
        <local:MainViewModel/>
    </Window.DataContext>


    <Grid>
        <oxy:PlotView Model="{Binding MyModel}"/>
    </Grid>
</Window>


public class MainViewModel
    {
    public MainViewModel()
        {
        this.MyModel = new PlotModel { Title = "Example 1" };
        this.MyModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
        }

    public PlotModel MyModel { get; private set; }
    }

这对我很有帮助。

这适用于全新的oxyplot 2.1.0版本,所有其他文档都已过时。 - Adison

1
我遇到了同样的问题。 所以我做的是将我的 "OxyPlot.Wpf" 版本降级到 1.0.0。你提到的示例现在可以正常工作,不再出现 "命名空间中不存在 plot 的名称" 的错误。
 <oxy:Plot x:Name="Plot1" Title="A Graph" Model="{Binding PlotModel}" Margin="10" Grid.Row="1">
    </oxy:Plot>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接