My UI did not response for orientation change

lak1104lak1104 Member ✭✭
edited March 13 in Xamarin.Forms

I am developing a native mobile app for all platforms. I have created my own theme content page. Then after deployment on android when I make phone landscape it did not respond. what's the reason here.

Here is my base content page.

                   public abstract class BaseContentPage : ContentPage
public readonly BaseViewModel BaseViewModel;

protected bool _isNavigated = false;

public BaseContentPage(BaseViewModel baseViewModel)
    BaseViewModel = baseViewModel;

public abstract void Navigate(SelectedItemChangedEventArgs e);
protected abstract override void OnAppearing();
protected override void OnDisappearing()
    _isNavigated = true;

public BaseContentPage()


here Xaml



        x:Class="DipsDemoXaml.Views.WardListPage" Title="{x:Static Resource:AppResources.WardListPageTitle}">
                  <StackLayout BackgroundColor="{StaticResource DefaultBackgroundColor}" Orientation="Vertical" x:Name="s1">

I even try this also in code behind constructor I call size changed and create a method called Wardpagesizechanged.

    public WardListPage(WardListPageViewModel wardListViewModel) : base(wardListViewModel)
    this.SizeChanged += wardpagesizechanged;

         Wardpagesizechanged method

  private void wardpagesizechanged(object sender, EventArgs e)
   if(this.Width> this.Height)
        s1.Orientation = StackOrientation.Horizontal;
        s1.Orientation = StackOrientation.Vertical;

what is the problem here, I am clueless


  • ColeXColeX Member, Xamarin Team Xamurai

    Try to use OnSizeAllocated instead.
    Note that the OnSizeAllocated method may be called many times when a device is rotated.

    Refer the solution for reacting to Changes in Orientation (StackLayout)

    protected override void OnSizeAllocated (double width, double height){
        base.OnSizeAllocated (width, height);
        if (width != this.width || height != this.height) {
            this.width = width;
            this.height = height;
            if (width > height) {
                outerStack.Orientation = StackOrientation.Horizontal;
            } else {
                outerStack.Orientation = StackOrientation.Vertical;

Sign In or Register to comment.