We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set the drawer width dynamically

Thread ID:





142474 Feb 5,2019 07:02 PM UTC Feb 9,2019 09:54 AM UTC Xamarin.Forms 3
Tags: SfNavigationDrawer
Asked On February 5, 2019 07:02 PM UTC

In the Xamarin.Forms Navigation Drawer samples, the drawer width is set dynamically based on the screen width:

 defaultDrawer.DrawerWidth = (float)(Core.SampleBrowser.ScreenWidth * 0.8);

But the way ScreenWidth is determined is hidden inside the Core.SampleBrowser library.

How can I set the drawer width according to the screen size? I can only get the screen width in pixels, but the DrawerWidth requires a float.



Replied On February 6, 2019 11:54 AM UTC

I got it working like this, in my case I just wanted the drawer to be 40 pixels less than the width of the screen.

   var metrics = DeviceDisplay.MainDisplayInfo;

    navigationDrawer.DrawerWidth = System.Convert.ToSingle(metrics.Width) / (System.Convert.ToSingle(metrics.Density)) - 40f;

Replied On February 6, 2019 05:35 PM UTC

Thanks for that Nick, that's interesting. 

Clearly Syncfusion has done it in a cross-platform way (although I haven't tried the Drawer in iOS, so I'm making assumptions there). It's a pity they don't reveal the method, as I've searched for a solution everywhere.

But your solution might be the answer I'm looking for - I'll give it a try.

Thanks again

Mugundhan Saravanan [Syncfusion]
Replied On February 9, 2019 09:54 AM UTC

Hi Paul,

Greetings from Syncfusion.

We can take the overall screen width and height of the device, this has been explained on the below stackoverflow link.


On our SfNavigationDrawer we need to set the width based on your requirement as mentioned below.

defaultDrawer.DrawerWidth = App.ScreenWidth/2;

We have modified a sample for the same, please download it from the link given below.

Sample link : http://www.syncfusion.com/downloads/support/forum/142474/ze/SfNavigationDrawerSample-1031154501

Mugundhan S.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon