简体   繁体   English

OxyPlot未以Xamarin形式显示

[英]OxyPlot not showing in Xamarin Forms

There are dozens of issues about this particular problem, but none of the proposed solutions have worked for me. 关于这个特定问题有很多问题,但是没有一个建议的解决方案对我有用。 I cannot get OxyPlot to appear in iOS or Android. 我无法让OxyPlot出现在iOS或Android中。 I've followed the setup instructions to add the various Init methods after Xamarin Forms init. 我已按照设置说明在Xamarin Forms init之后添加各种Init方法。 What I have tried so far: 到目前为止我尝试过的是:

  • Adding HeightRequest + WidthRequest 添加HeightRequest + WidthRequest
  • Not putting it in a stack layout 不将其放在堆栈布局中
  • Adding a dummy variable after init 在初始化之后添加一个虚拟变量
  • Going to the latest unstable version via OxyPlot's nuget feed ( https://www.myget.org/F/oxyplot ) 通过OxyPlot的nuget feed转到最新的不稳定版本( https://www.myget.org/F/oxyplot

I am using Xamarin Android version 25.4.0.2, Xamarin Forms 2.4.0.18342, and OxyPlot version 1.0.0. 我正在使用Xamarin Android版本25.4.0.2,Xamarin Forms 2.4.0.18342和OxyPlot版本1.0.0。

Here's the XAML: 这是XAML:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms"
        x:Class="Example.Stats"
        NavigationPage.HasNavigationBar="false">
    <ContentPage.Content>
        <AbsoluteLayout>  
            <oxy:PlotView Model="{Binding Model}"  
                  AbsoluteLayout.LayoutBounds="20,0,.9,.9" AbsoluteLayout.LayoutFlags="WidthProportional,HeightProportional" />  
        </AbsoluteLayout>  
    </ContentPage.Content>
</ContentPage>

And the partial class: 和偏类:

namespace Gatemaster
{
    public partial class Stats : ContentPage
    {
        public PlotModel Model { 
            get {
                var model = new PlotModel { Title = "World population by continent" };  
                var ps = new PieSeries  
                {        
                    StrokeThickness = .25,  
                    InsideLabelPosition = .25,  
                    AngleSpan = 360,  
                    StartAngle = 0  
                };  

                // http://www.nationsonline.org/oneworld/world_population.htm  
                // http://en.wikipedia.org/wiki/Continent  
                ps.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = false });  
                ps.Slices.Add(new PieSlice("Americas", 929) { IsExploded = false });  
                ps.Slices.Add(new PieSlice("Asia", 4157));  
                ps.Slices.Add(new PieSlice("Europe", 739) { IsExploded = false });  
                ps.Slices.Add(new PieSlice("Oceania", 35) { IsExploded = false });  
                model.Series.Add(ps);
                return model;
            } 
            private set { 

            } 
        }

        public Stats()
        {
            InitializeComponent();
        }
    }
}

As per @Jason, I missed setting BindingContext. 按照@Jason,我错过了设置BindingContext。 I find it incredibly odd that an error wasn't being thrown about a missing property... 我发现没有因为缺少财产而引发错误,这真是令人难以置信。

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

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