gpt4 book ai didi

.net - OxyPlot 无法在 Xamarin Forms UWP 中呈现

转载 作者:行者123 更新时间:2023-12-03 04:47:14 24 4
gpt4 key购买 nike

已关注 this简单的示例我只是在玩将 OxyPlot 嵌入到 Xamarin Forms 示例应用程序中。我创建了一个全新的 Xamarin Forms 应用程序,添加了 Nuget 包,并在每个项目中添加了 OxyPlot 所需的初始化代码。然后,在我的 MainPage.xaml 中,我有:

<?xml version="1.0" encoding="utf-8" ?>
<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"
xmlns:local="clr-namespace:OxyPlotTestApp"
x:Class="OxyPlotTestApp.MainPage">

<AbsoluteLayout>
<oxy:PlotView Model="{Binding PieModel}" AbsoluteLayout.LayoutBounds="20,0,.9,.9"
AbsoluteLayout.LayoutFlags="WidthProportional,HeightProportional" />
</AbsoluteLayout>

</ContentPage>

在代码隐藏中:

using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using OxyPlot.Xamarin.Forms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace OxyPlotTestApp
{
public class PieViewModel
{
public PlotModel PieModel { get; set; }

public PieViewModel()
{
PieModel = CreatePieChart();

}

private PlotModel CreatePieChart()
{
var model = new PlotModel { Title = "World Population By Content" };
var ps = new PieSeries
{
StrokeThickness = .25,
InsideLabelPosition = 0.25,
AngleSpan = 360,
StartAngle = 0
};
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;
}

}
public partial class MainPage : ContentPage
{
public PieViewModel vm { get; set; }
public MainPage()
{
InitializeComponent();
vm = new PieViewModel();
this.BindingContext = vm;
}

}
}

我不确定我错过了什么(如果有的话),但我尝试过 UWP 项目和 Android 项目(后者在物理设备上),并且它在 Android 上很好,但 UWP 应用程序只是呈现空白页面。

我的UWP App.xaml.cs(相关部分):

if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;

OxyPlot.Xamarin.Forms.Platform.UWP.PlotViewRenderer.Init();

Xamarin.Forms.Forms.Init(e);

谢谢...

编辑:

我刚刚创建了一个新的测试项目并获得了完全相同的结果,因此它不是特定于我的项目或机器......

最佳答案

我遇到了与您提到的相同的问题,PieChart 可在 Android 上运行,但无法在使用 Xamarin.Forms (3.1.0.697729) 的 UWP 上运行。我最终通过安装 here 中的最新版本的 OxyPlot.Xamarin.Forms 使其在 UWP 上运行。而不是 1.0.0。它适用于饼图,我没有测试其他图。

此外,Oxyplot 文档 here说“必须设置 VerticalOptions 和 Horizo​​ntalOptions 属性”,但您还需要设置 HeightRequest 和 WidthRequest。我在这个post中读到了这一点,但与这篇文章相反,它在 StackLayout 中对我来说工作得很好。这个问题很老了,但我希望它能有所帮助!

关于.net - OxyPlot 无法在 Xamarin Forms UWP 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44676912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com