0

The below code properly work on Android but it' throws null exception on iOS.On ios first select it's not loading the page and when you select another item on list after the first selection it will load that page. My code is given below.

menuPage.Menu.ItemSelected += (sender, e) =>
{
    NavigateTo(e.SelectedItem as Drawer_MenuItem,sender);
};

private void NavigateTo(Drawer_MenuItem menu,Object se)
{
    Page displayPage = (Page)Activator.CreateInstance(menu.TargetType);
    this.Detail = new NavigationPage(displayPage);

    IsPresented = false;

    if (menu != null)
    {
        if (menuPage.Menu.SelectedItem != null)
        {
            ((ListView)se).SelectedItem = null;
        }
    }
}

UPDATE :

I have found the bug but did't get any solution. The bug is in custom render which is used for custom stack layout and entry. If I remove custom render It is working fine.Otherwise it is having the same problem.

Please help me with this problem using custom render.

Code for custom render:

[assembly:ExportRenderer(typeof(Custom_StackLayout),typeof(CustomStackLayoutRenderer))]

namespace LIVI.iOS.Renderers
{
    public class CustomStackLayoutRenderer : VisualElementRenderer<Custom_StackLayout>
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Custom_StackLayout> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement.ClassId == "noborder")
            {
                Layer.CornerRadius = 15;
                Layer.BorderColor = Color.FromHex("#e57593").ToCGColor();
                Layer.BorderWidth = 1;
                Layer.MasksToBounds = true;
            }
            else if(e.NewElement.ClassId== "noborderDriverInfo")
            {
                Layer.CornerRadius = 15;
                Layer.MasksToBounds = true;
            }
            else if(e.NewElement.ClassId== "btn_viewProfile")
            {
                Layer.CornerRadius = 15;
                Layer.BorderColor = Color.White.ToCGColor();
                Layer.BorderWidth = 1;
                Layer.MasksToBounds = true;
            }
            else if (e.NewElement.ClassId == "filledStackLayout")
            {

                Layer.CornerRadius = 5;
                Layer.BorderColor = Color.Transparent.ToCGColor();
                Layer.BorderWidth = 0;
                Layer.MasksToBounds = true;
            }
            else if (e.NewElement.ClassId == "imgborder")
            {
                Layer.CornerRadius = 10;
                Layer.BorderWidth = 2;
                Layer.BorderColor = Color.FromHex("#FFC600").ToCGColor();
                Layer.MasksToBounds = true;
            }
            else if (e.NewElement.ClassId == "conDriverMob")
            {
                Layer.CornerRadius = 10;
                Layer.BorderWidth = 2;
                Layer.BorderColor = Color.FromHex("#e9eaeb").ToCGColor();
                Layer.MasksToBounds = true;
            }
            else if (e.NewElement.ClassId == "imgBtn")
            {
                Layer.CornerRadius = 10;
                Layer.BorderWidth = 3;
                Layer.BorderColor = Color.White.ToCGColor();
                Layer.MasksToBounds = true;
            }
            else if (e.NewElement.ClassId == "cellWrapper")
            {
                Layer.CornerRadius = 1;
                Layer.BorderWidth = 2;
                Layer.BorderColor = Color.FromHex("#e9eaeb").ToCGColor();
                Layer.MasksToBounds = true;

            }
            else if (e.NewElement.ClassId == "sqBorder")
            {
                Layer.BorderWidth = 2;
                Layer.BorderColor = Color.FromHex("#e9eaeb").ToCGColor();
                Layer.MasksToBounds = true;
            }
            else
            {
                Layer.CornerRadius = 15;
                Layer.BorderWidth = 2;
                Layer.BorderColor = Color.White.ToCGColor();
                Layer.MasksToBounds = true;

            }
        }
    }
}
Mayur Kerasiya
  • 206
  • 1
  • 9
  • 1
    On what line is the exception given? Also what is the `Drawer_MenuItem` object? It sounds like a Android specific type of object. – Gerald Versluis Apr 07 '17 at 10:30
  • Do you want an Master Page detail xamarin cross. You could try the next working example: https://github.com/EliasMerabet/Net/tree/master/Xamarin/Cross/NavigationDrawer. Please, let me know any doubt. – Kenzo_Gilead Apr 07 '17 at 11:04
  • @GeraldVersluis it throws error at this.Detail = new NavigationPage(displayPage); and GileadKenzo i have tried the code which you have given but it throws same error on ios only – Mayur Kerasiya Apr 10 '17 at 05:23
  • Try adding a `null` check either in the `NavigateTo` or the `ItemSelected` handler. It seems that you are setting the `SelectedItem` back to null which triggers the `ItemSelected` handler again, which in his turn fires the `NavigateTo` with null as a parameter. – Gerald Versluis Apr 10 '17 at 06:49
  • If you want help with the custom renderer, we are going to need the code. – Gerald Versluis Apr 10 '17 at 07:34
  • @GileadKenzo i have added the custom render code of stack layout – Mayur Kerasiya Apr 10 '17 at 07:44

0 Answers0