Xamarin.forms: Setting width of master page is not working for tablet.

Created on 16 Dec 2019  路  4Comments  路  Source: xamarin/Xamarin.Forms

Description

I am trying to change width of master page in landscape mode for tablet. I have used renderer for that. Using that i am able to change the master page width in mobile phone. But it is not working for tablet.

Steps to Reproduce

  1. Create one xamarin forms project in Master-Detail template.
    2.Create MasterDetailPagePCL class fro renderer.

    public class MasterDetailPagePCL : MasterDetailPage
    {
    public static readonly BindableProperty DrawerWidthProperty =
    BindableProperty.Create("DrawerWidth", typeof(float),
    typeof(MasterDetailPagePCL), 0.1f, BindingMode.TwoWay, null);

    public float DrawerWidth
    {
        get { return (float)GetValue(DrawerWidthProperty); }
        set { SetValue(DrawerWidthProperty, value); }
    }
    

    }

  2. In Android project I have added this renderer.

    public class MasterDetailAndroidRenderer : MasterDetailRenderer
    {
    public MasterDetailAndroidRenderer(Context context) : base(context)
    {

    }
    
    public override void AddView(Android.Views.View child)
    {
    
        MasterDetailPagePCL page = (MasterDetailPagePCL)this.Element;
        LayoutParams p = (LayoutParams)child.LayoutParameters;
    
        p.Width = 160;
    
        base.AddView(child,p);
    }
    

    }

  3. Deploy this project in tablet.
  4. Rotate tablet to landscape mode.

Expected Behavior

  1. It's master page should get fixed(Which is working fine).
  2. Width of master page should get changed as per the "DrawerWidth" peoperty.

    Actual Behavior

  3. Width of master page not changing as per the "DrawerWidth" peoperty.

    Basic Information

Xamarin Forms version: 4.4.0.991265

Screenshots

Reproduction Link

4 help wanted inactive Android tablet bug up-for-grabs

Most helpful comment

Is there any update on this ? Can you please give us any workaround to resolve the issue? Please make it as priority

All 4 comments

@13atec030 Can you please attach a small project that demonstrates this issue? Thanks!

Hi Samhouts,

i am unable to add the sample . i am reproducing this issue in the default master detail template sample . Also Set MasterBehaviour as SplitOnLandscape Please look into this.

In PCL, add one custom file

public class MasterDetailPagePCL : MasterDetailPage
{
public static readonly BindableProperty DrawerWidthProperty =
BindableProperty.Create("DrawerWidth", typeof(float),
typeof(MasterDetailPagePCL), 0.1f, BindingMode.TwoWay, null);

 public float DrawerWidth
 {
     get { return (float)GetValue(DrawerWidthProperty); }
     set { SetValue(DrawerWidthProperty, value); }
 }
}

And in android renderer, add renderer file

public class MasterDetailAndroidRenderer : MasterDetailRenderer
{
public MasterDetailAndroidRenderer(Context context) : base(context)
{ }
    public override void AddView(Android.Views.View child)
    {

        MasterDetailPagePCL page = (MasterDetailPagePCL)this.Element;
        LayoutParams p = (LayoutParams)child.LayoutParameters;

        p.Width = 160;

        base.AddView(child,p);
    }
}

Thanks inadvance

I can reproduce this issue
App22.zip

Is there any update on this ? Can you please give us any workaround to resolve the issue? Please make it as priority

Was this page helpful?
0 / 5 - 0 ratings