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

Application Current Width

public partial class GridLayoutPage : ContentPage
{
  protected override void OnSizeAllocated(double width, double height) 
  { 
    base.OnSizeAllocated(width, height); 
 
    if (width > 0 && pageWidth != width) 
    {       
        var size = Application.Current.MainPage.Width / listView.ItemSize; 
        gridLayout.SpanCount = (int)size; 
        listView.LayoutManager = gridLayout; 
     } 
  }
}

Application.Current.MainPage.Width show -1 , please ad


1 Reply

SY Suthi Yuvaraj Syncfusion Team October 14, 2022 09:45 AM

Hi Anson,


We suspect that you have initialized the MainPage as AppShell in App.xaml.cs, we suggest you to set the MainPage as page which you want to get the size , Please refer the below code snippet for more understanding


Code snippet:

public partial class App : Application

{

       public App()

       {

             InitializeComponent();

 

             MainPage = new MainPage();

       }

}


Also If you want to
initialize the MainPage as AppShell , you can get the width from the mainPage, we have attached the code snippet for more reference.


Code snippet:

protected override void OnSizeAllocated(double width, double height)

{

    base.OnSizeAllocated(width, height);

    if (width > 0 && pageWidth != width)

    {

        var size = this.Width / listView.ItemSize;

        gridLayout.SpanCount = (int)size;

        listView.LayoutManager = gridLayout;

    }

}



If you still facing the issue , please share the details of ContentPage and listview details which will be more helpful for us to find the solution as soon as possible.


Regards,

Suthi Yuvaraj.


Loader.
Live Chat Icon For mobile
Up arrow icon