【问题标题】:How can I pass parameters from RootPageMenuItem to Constructer of Content Page?如何将参数从 RootPageMenuItem 传递给内容页面的构造函数?
【发布时间】:2019-07-17 11:52:57
【问题描述】:

我有问题。我的问题是我无法将参数从 RootPageMenuItem 传递给内容页面的构造函数。

我的代码:

new RootPageMenuItem { Id = 4, Title = "myTitle", ImageSource = "rightArrow.png", TargetType = typeof(myContentPage) },

我想实现这个:

new RootPageMenuItem { Id = 4, Title = "myTitle", ImageSource = "rightArrow.png", TargetType = typeof(myContentPage(_param1,_param2)) },

我该怎么做?

【问题讨论】:

    标签: xamarin.forms master-detail


    【解决方案1】:

    解决方案:

    if(item.TargetType == typeof(myContentPage))
    {
        //This will create instance of the page using the parameterized constructor you defined in each DetailPages
    Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType, param1 ,param2));
    }
    else
    {
        Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType));
    }
    
    

    这里有一个类似的issue,你可以参考一下。

    【讨论】:

    • 快乐编码:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    相关资源
    最近更新 更多