繁体   English   中英

C# WPF OxyPlot 错误 plot 在命名空间中不存在

[英]C# WPF OxyPlot error plot does not exist in namespace

您好,我在 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();
    }
}
}

主窗口模型.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));
    }
}
}

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

从 lib 版本 1.x 迁移到 2.1 时,我遇到了来自 NuGet 的 OxyPlot lib 的相同问题。 所以我发现,在 2.1 版中, Plot class 被移动到另一个库,请参阅其 github 页面上的发布历史记录。 这对我有用:

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

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

<oxycontrols:Plot.../>

<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.Wpf”降级到 1.0.0 版。 并且您所说的示例工作正常,没有错误“命名空间中不存在名称 plot”。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM