【问题标题】:OxyPlot not showing in Xamarin FormsOxyPlot 未在 Xamarin 表单中显示
【发布时间】:2018-04-06 21:47:58
【问题描述】:

关于这个特定问题有几十个问题,但没有一个建议的解决方案对我有用。我无法让 OxyPlot 出现在 iOS 或 Android 中。我已按照设置说明在 Xamarin Forms init 之后添加各种 Init 方法。到目前为止我尝试过的:

  • 添加 HeightRequest + WidthRequest
  • 不将其放入堆栈布局中
  • 在初始化后添加一个虚拟变量
  • 通过 OxyPlot 的 nuget feed (https://www.myget.org/F/oxyplot) 转到最新的不稳定版本

我正在使用 Xamarin Android 版本 25.4.0.2、Xamarin Forms 2.4.0.18342 和 OxyPlot 版本 1.0.0。

这是 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>

以及部分类:

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();
        }
    }
}

【问题讨论】:

  • 你似乎没有设置你的 BindingContext
  • @Jason 在这种情况下需要这样做吗?我之前已经能够绑定到部分类的属性而无需设置它。
  • AFAIK,您可以显式设置或继承它,但必须在某处设置
  • 您是否尝试过将垂直和水平选项同时设置为居中和高度/宽度请求?我有一个网格,这对我有用:
  • @Jason:Welp,你是对的。初始化程序中的BindingContext = this; 使图表出现。

标签: c# xamarin.forms oxyplot


【解决方案1】:

根据@Jason,我错过了设置 BindingContext。我发现对于缺少的属性没有抛出错误感到非常奇怪......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-14
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多