OxyPlot not showing in Xamarin Forms

强颜欢笑 提交于 2019-12-11 05:52:15

问题


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. I've followed the setup instructions to add the various Init methods after Xamarin Forms init. What I have tried so far:

  • Adding 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)

I am using Xamarin Android version 25.4.0.2, Xamarin Forms 2.4.0.18342, and OxyPlot version 1.0.0.

Here's the 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();
        }
    }
}

回答1:


As per @Jason, I missed setting BindingContext. I find it incredibly odd that an error wasn't being thrown about a missing property...



来源:https://stackoverflow.com/questions/46938602/oxyplot-not-showing-in-xamarin-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!