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

Crash if using list view with NavigationDrawer

I run Xamarin Studio on Mac. I can also run SampleBrowser-Form project without any problem.
But when I try to write my own app using SfNavigationDrawer, the app always crash when it try to render NavigationDrawer. If I don't add ListView to DrawerContentView it will run fine.

My code:

    public partial class LogoutPage : ContentPage
    {
        AuthenticationResult authenticationResult;

        public LogoutPage(AuthenticationResult result)
        {
            InitializeComponent();
            authenticationResult = result;
            ObservableCollection<String> list = new ObservableCollection<string>();
            list.Add("Home");
            ListView listView = new ListView();
            listView.ItemsSource = list;

            var maincontent = new MainContentView_Default();
            StackLayout mainStack = new StackLayout();
            mainStack.Opacity = 1;
            mainStack.Orientation = StackOrientation.Vertical;
            mainStack.HeightRequest = 500;
            mainStack.BackgroundColor = Color.Black;
            //If I comment out below line, the app will run normal
            mainStack.Children.Add(listView);
            navigationDrawer.DrawerContentView = mainStack;
            navigationDrawer.ContentView = maincontent.Content;
            navigationDrawer.DrawerHeaderView = getDrawerheader();
            navigationDrawer.DrawerWidth = 200;
            navigationDrawer.DrawerHeaderHeight = 150;
            navigationDrawer.DrawerFooterHeight = 0;
            navigationDrawer.DrawerHeight = (float)App.ScreenHeight;
            navigationDrawer.Duration = 400;
            navigationDrawer.Position = Position.Left;
            navigationDrawer.Transition = Syncfusion.SfNavigationDrawer.XForms.Transition.SlideOnTop;
            navigationDrawer.TouchThreshold = 100;
        }
        public View getDrawerheader()
        {
            StackLayout headerLayout = new StackLayout();
            headerLayout.Orientation = StackOrientation.Vertical;
            headerLayout.BackgroundColor = Color.FromHex("#1aa1d6");
            headerLayout.VerticalOptions = LayoutOptions.CenterAndExpand;
            headerLayout.HorizontalOptions = LayoutOptions.CenterAndExpand;
            headerLayout.HeightRequest = 200;
            headerLayout.WidthRequest = 275;
            Image emp = new Image();
            emp.Source = ImageSource.FromFile("user.png");
            emp.HeightRequest = 100;
            emp.WidthRequest = 70;
            emp.HorizontalOptions = LayoutOptions.CenterAndExpand;
            emp.VerticalOptions = LayoutOptions.Center;
            emp.BackgroundColor = Color.FromHex("#1aa1d6");
            headerLayout.Children.Add(emp);

            Label header = new Label();
            header.Text = "James Pollock";
            header.FontSize = 20;
            header.HeightRequest = 30;
            header.WidthRequest = 140;
            header.TextColor = Color.White;
            header.HorizontalOptions = LayoutOptions.Center;
            header.VerticalOptions = LayoutOptions.Center;
            header.BackgroundColor = Color.FromHex("#1aa1d6");
            headerLayout.Children.Add(header);
            return headerLayout;
        } 
}

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:navigation="clr-namespace:Syncfusion.SfNavigationDrawer.XForms;assembly=Syncfusion.SfNavigationDrawer.XForms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="ADB2CAuthorization.LogoutPage" Title="Logout">
    <navigation:SfNavigationDrawer BackgroundColor="White" x:Name="navigationDrawer" >
    </navigation:SfNavigationDrawer>
</ContentPage>
  

 Please advice me how to avoid the crash. Thank you.

Attachment: Screen_Shot_20161110_at_1.45.44_PM_97af304e.zip

1 Reply

PK Pavendhan Kumar Syncfusion Team November 11, 2016 11:54 AM UTC

Hi Long,

We would like to inform that the issue "Adding list view in NavigationDrawer’s throws exception" is occurring due to Xamarin Forms latest version (i.e.2.3.1.127). We request you to use the older version (i.e.2.3.1.114) of Xamarin forms till the has been resolved. And also there is a query already raised in Xamarin forum regarding the same. Please find the link for the query.

https://forums.xamarin.com/discussion/80549/android-listview-crashes-not-on-ios-or-uwp 

And We have filed a bug report about "adding a list view in NavigationDrawer crashes the app on Xamarin.Forms Android platform" and please find the link for the report
below.

Link: https://bugzilla.xamarin.com/show_bug.cgi?id=46563 

Regards,
Pavendhan K. 


Loader.
Up arrow icon