【问题标题】:Trying to add OxyPlot to a Xamarin Forms xaml Page尝试将 OxyPlot 添加到 Xamarin Forms xaml 页面
【发布时间】:2015-04-09 23:55:33
【问题描述】:

我试图将 oxyplot 包含到 Xamarin.Forms-Project 中

这是我构建 PlotModel 的 Xaml.cs 文件。

private void GeneratePlot()
    {
        var Points = new List<DataPoint>
        {
            new DataPoint(0, 0),
            new DataPoint(10, 5),
            new DataPoint(20, 10),
            new DataPoint(30, 16),
            new DataPoint(40, 12),
            new DataPoint(50, 19)
        };
        var Points2 = new List<DataPoint>
        {
            new DataPoint(0, 0),
            new DataPoint(10, 7),
            new DataPoint(20, 8),
            new DataPoint(30, 8),
            new DataPoint(40, 20),
            new DataPoint(50, 25)
        };
        var m = new PlotModel();
        m.PlotType = PlotType.XY;
        m.InvalidatePlot(true);
        m.Title = "hello oxy";
        m.ResetAllAxes();
        var ls1 = new LineSeries();
        var ls2 = new LineSeries();
        ls1.ItemsSource = Points;
        ls2.ItemsSource = Points2;

        m.Series.Add(ls1);
        m.Series.Add(ls2);
        var _opv = new OxyPlotView
        {
            WidthRequest = 300,
            HeightRequest = 300,
            BackgroundColor = Color.Aqua
        };
        _opv.Model = m;
        PlModel = m;
    }

在代码中,当我将 OxyPlotModel _opy 放入 StackLayout 时,它可以正常工作。 但是当我要像这样将它添加到 Xaml 中时:

 <oxy:PlotView Model="{Binding Model}" VerticalOptions="Center" HorizontalOptions="Center" />

我得到以下异常:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: An exception was thrown by the type initializer for OxyPlot.XamarinForms.PlotView ---> System.MissingMethodException: Method not found: 'Xamarin.Forms.BindableProperty.Create'.

有谁知道我可以做些什么来将 OxyPlot 与 Xaml 一起使用?

非常感谢

【问题讨论】:

    标签: xaml xamarin.forms oxyplot


    【解决方案1】:

    确保您拥有的 OxyPlot 版本与您拥有的 Forms 版本兼容。

    过去我不得不手动下载 OxyPlot 源并更新 Xamarin.Forms NuGet。

    【讨论】:

    • 如何知道它们是否兼容?
    • NuGet 包通常会在描述中说明它与哪个版本兼容。您使用的是哪个版本的表单?哪个版本的 Oxy?
    • 嗨,在我的参考资料中 Xamarin.Forms.Core 和 Xamarin.Forms.Xaml 是 1.4 Xamarin.Forms.Platform 是 1.0。 OxyPlot 和 OxyPlot.XamarinForms 是 2014.1.517.0
    猜你喜欢
    • 1970-01-01
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多