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