【发布时间】:2017-12-25 23:23:28
【问题描述】:
我已在 Xamarin.Forms 中使用 oxyplot 成功生成了一个绘图,但我无法停止 oxyplot 获取整个页面。
我在轮播中的其他页面上使用 stacklayout,并在每个页面上都有一个横幅作为嵌入式 stacklayout,并且希望该图出现在其下方的嵌入式 stacklayout 中。
但横幅会短暂出现,然后被 oxyplot 覆盖。
我发现应该使用 Grid 而不是 stacklayout,因为存在已知问题,但 grid 也不起作用。
感谢您的任何帮助!这可能是一个绑定问题,例如,如果我删除 Model="{Binding Model}" 它仍然有效!它忽略了 HeightRequest="100" 而只是填充页面。我显然在这里遗漏了一些东西。
这是xaml代码,我已经注释掉了网格尝试,“oxy:PlotView”中的各种选项是我最后一次尝试的:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="RentGuru2.PieCosts"
xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms"
Padding="0, 20, 0, 0"
BackgroundColor="#21b09c">
<StackLayout Orientation="Vertical">
<StackLayout Orientation="Horizontal" BackgroundColor="#21b09c" HeightRequest="60">
<Image Source = "BannerLogo.png" />
<Label Text="Costs breakdown" FontSize="Large" TextColor="White" Margin="10" VerticalTextAlignment="Center"/>
</StackLayout>
<StackLayout HeightRequest="300">
<oxy:PlotView Model="{Binding Model}" VerticalOptions="Center" HorizontalOptions="FillAndExpand"
HeightRequest="100" WidthRequest="100" />
</StackLayout>
</StackLayout>
<!--<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Grid.Column ="0" Source = "BannerLogo.png" />
<Label Grid.Row="0" Grid.Column ="1" Text="Costs breakdown" FontSize="Large" TextColor="White" Margin="10" VerticalTextAlignment="Center"/>
<oxy:PlotView Grid.Row="1" Grid.ColumnSpan ="2" Model="{Binding Model}" VerticalOptions="Center" HorizontalOptions="Center" />
</Grid>-->
</ContentPage>
这是相关的oxyplot xaml.cs代码:
namespace RentGuru2
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class PieCosts : ContentPage
{
public PieCosts ()
{
InitializeComponent ();
}
protected override void OnAppearing()
{
Content = new PlotView
{
Model = CreatePieChart()
};
}
private PlotModel CreatePieChart()
{
var model = new PlotModel
{
Title = "Costs breakdown",
Padding = new OxyThickness(50, 30, 50, 40),
TitleFontSize = 22,
TitleColor = OxyColors.White
//Title = "",
//Padding = new OxyThickness(50, 30, 50, 40),
//TitleFontSize = 1,
//TitleColor = OxyColors.White,
};
var ps = new PieSeries
{
StrokeThickness = .25,
InsideLabelPosition = .8,
AngleSpan = 360,
StartAngle = 0,
LabelField = "{2:0.0}",
FontSize = 15,
TextColor = OxyColors.White
};
【问题讨论】:
-
OnAppearing()将整个页面的Content替换为PlotView... 所以,你得到了你想要的......:O)
标签: c# xaml xamarin.forms oxyplot