OxyPlot没有以Xamarin形式显示 [英] OxyPlot not showing in Xamarin Forms
问题描述
关于这个特定问题有很多问题,但是没有一个建议的解决方案对我有用.我无法使OxyPlot出现在iOS或Android中.我已经按照设置说明在Xamarin Forms init之后添加各种Init方法.到目前为止,我已经尝试过:
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:
- 添加HeightRequest + WidthRequest
- 不将其放置在堆栈布局中
- 在init之后添加虚拟变量
- 通过OxyPlot的nuget提要转到最新的不稳定版本( https://www.myget.org/F/oxyplot )
- 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)
我正在使用Xamarin Android 25.4.0.2版,Xamarin Forms 2.4.0.18342和OxyPlot 1.0.0版.
I am using Xamarin Android version 25.4.0.2, Xamarin Forms 2.4.0.18342, and OxyPlot version 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();
}
}
}
推荐答案
根据@Jason,我错过了设置BindingContext的权限.我非常奇怪,没有因为缺少属性而引发错误...
As per @Jason, I missed setting BindingContext. I find it incredibly odd that an error wasn't being thrown about a missing property...
这篇关于OxyPlot没有以Xamarin形式显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!