视图在旋转时不会调整大小

时间:2016-03-22 14:09:45

标签: c# windows-phone xamarin.forms

我在shared app

中有xamarin.forms

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;

using Xamarin.Forms;

namespace MyFin1.Views.Reports
{
    public class Reports_view : ContentPage
    {
        StackLayout Lay = new StackLayout();
    public Reports_view ()
    {
        NavigationPage.SetHasNavigationBar(this, true);
        Lay.Children.Add(
              new Xamarin.Forms.Label
              {
                  Text = "Мои Финансы",
                  TextColor = Color.FromRgb(200, 200, 200),
                  HorizontalOptions = LayoutOptions.FillAndExpand,
                  VerticalOptions = LayoutOptions.Center,
                  FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Xamarin.Forms.Label)),
                  FontAttributes = FontAttributes.Bold | FontAttributes.Italic,
                  BackgroundColor=Color.Aqua
              }
           );
        Button Bar_chart_go = new Button
        {
            Text = "Динамика",
            BackgroundColor = Color.Red,
            HorizontalOptions = LayoutOptions.FillAndExpand
        };
        Button Pie_chart_go = new Button
        {
            Text = "Структура",
            BackgroundColor = Color.Green,
            HorizontalOptions = LayoutOptions.FillAndExpand
        };
        Bar_chart_go.Clicked += Bar_chart_go_Clicked;
        Pie_chart_go.Clicked += Pie_chart_go_Clicked;

        Lay.Children.Add(Bar_chart_go);
        Lay.Children.Add(Pie_chart_go);

        Content = new StackLayout {
            BackgroundColor=Color.Maroon,
            HorizontalOptions = LayoutOptions.FillAndExpand,

            Children = {

                Lay
            }
        };    
    }
}
Android模拟器上的

一切正常(旋转屏幕时 - 旋转视图) enter image description here

enter image description here

在Windows Phone(诺基亚530)上存在问题:

enter image description here

enter image description here

MainPage.xaml.cs我有SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;

如果我旋转然后导航到页面所有作品都很好。 enter image description here

有办法解决吗?

其他信息

Xamarin.Forms 2.0.1.6505

PS原始问题RU_SO

1 个答案:

答案 0 :(得分:0)

也许这会有所帮助:

在构造函数中:

this.SizeChanged += ModalPage_SizeChanged;

然后:

void ModalPage_SizeChanged (object sender, EventArgs e)
{
    this.WidthRequest = Width;
    this.HeightRequest = Height;

    Lay.WidthRequest = Width;
    Lay.HeightRequest = Height;
}
相关问题