locked
Detect current expansion of Master page RRS feed

  • Question

  • User360996 posted

    Hi all,

    Is there a way to figure out how much is Master page expanded in MasterDetails implementation?

    I need to update content as master page is expanding. In custom renderer I override OnDraw event, but all I can do is to check if master page is presented. No other property of master page seem to change as it expands/retracts.

    Friday, September 7, 2018 1:48 PM

Answers

  • User368901 posted

    Hi,

    As I understand you are targeting Android. If so, the MasterDetailPage will be translate into DrawerLayout and implements DrawerLayout.IDrawerListener interface. You can use OnDrawerSlide event inside your custom renderer to decide how much the master page has expanded:

    [assembly:ExportRenderer(typeof(MyMasterDetailPage),typeof(MyMasterDetailPageRenderer))]
    namespace Demo.Droid
    {
        public class MyMasterDetailPageRenderer:MasterDetailPageRenderer
        {
            public MyMasterDetailPageRenderer(Context c) : base(c)
            {
                //register the DrawerSlide event
                this.DrawerSlide += MyMasterDetailPageRenderer_DrawerSlide;
            }
    
            private void MyMasterDetailPageRenderer_DrawerSlide(object sender, DrawerSlideEventArgs e)
            {
                //the offset grows from 0 to 1 when opening the drawer and decrease from 1 to 0 when closing
                Console.WriteLine("SlideOffset= " + e.SlideOffset);
            }
        }
    }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, September 13, 2018 7:51 AM

All replies

  • User368901 posted

    Hi,

    As I understand you are targeting Android. If so, the MasterDetailPage will be translate into DrawerLayout and implements DrawerLayout.IDrawerListener interface. You can use OnDrawerSlide event inside your custom renderer to decide how much the master page has expanded:

    [assembly:ExportRenderer(typeof(MyMasterDetailPage),typeof(MyMasterDetailPageRenderer))]
    namespace Demo.Droid
    {
        public class MyMasterDetailPageRenderer:MasterDetailPageRenderer
        {
            public MyMasterDetailPageRenderer(Context c) : base(c)
            {
                //register the DrawerSlide event
                this.DrawerSlide += MyMasterDetailPageRenderer_DrawerSlide;
            }
    
            private void MyMasterDetailPageRenderer_DrawerSlide(object sender, DrawerSlideEventArgs e)
            {
                //the offset grows from 0 to 1 when opening the drawer and decrease from 1 to 0 when closing
                Console.WriteLine("SlideOffset= " + e.SlideOffset);
            }
        }
    }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, September 13, 2018 7:51 AM
  • User360996 posted

    Hi @ElvisXia, thanks for your answer, that is exactly what I needed.

    Thursday, September 13, 2018 8:37 AM