在Xamarin.Forms中的MasterDetailPage导航

时间:2017-04-07 10:06:13

标签: xamarin xamarin.ios xamarin.forms custom-renderer

下面的代码在Android上正常工作,但它'在iOS上抛出null异常。首先选择它不加载页面,当你在第一个选择后选择列表上的另一个项目时,它将加载该页面。我的代码如下。

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;
        }
    }
}

更新:

我发现了这个错误,但没有得到任何解决方案。 该错误在自定义渲染中,用于自定义堆栈布局和输入。 如果我删除自定义渲染它工作正常。否则它有同样的问题。

请使用自定义渲染帮我解决此问题。

自定义渲染代码:

[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;

            }
        }
    }
}

0 个答案:

没有答案