簡體   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