Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms Xamarin表单:如何将具有参数的contentpage添加到列表中?_Xamarin.forms_Navigation Drawer_Master Detail - Fatal编程技术网

Xamarin.forms Xamarin表单:如何将具有参数的contentpage添加到列表中?

Xamarin.forms Xamarin表单:如何将具有参数的contentpage添加到列表中?,xamarin.forms,navigation-drawer,master-detail,Xamarin.forms,Navigation Drawer,Master Detail,我正在我的项目上实现导航抽屉。为了这个特性,我遵循这个 Mainpage.xsml.cs: public partial class NavigationDrawerPage : MasterDetailPage { public List<MasterPageItem> menuList { get; set; } public MainPage() { InitializeComponent();

我正在我的项目上实现
导航抽屉
。为了这个特性,我遵循这个

Mainpage.xsml.cs:

public partial class NavigationDrawerPage : MasterDetailPage
    {
public List<MasterPageItem> menuList { get; set; }
        public MainPage()
        {
            InitializeComponent();

            menuList = new List<MasterPageItem>();

            // Adding menu items to menuList and you can define title ,page and icon
            menuList.Add(new MasterPageItem() { Title = "Home", Icon = "home.png", TargetType = typeof(HomePage) });
            menuList.Add(new MasterPageItem() { Title = "Setting", Icon = "setting.png", TargetType = typeof(SettingPage) });
            menuList.Add(new MasterPageItem() { Title = "LogOut", Icon = "logout.png", TargetType = typeof(LogoutPage) });

            navigationDrawerList.ItemsSource = menuList;

            Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(HomePage)));
        }
}
menuList.Add(new MasterPageItem() { Title = "Home", Icon = "home.png", TargetType = typeof(SettingPage) });
menuList.Add(new MasterPageItem() { Title = "Help", Icon = "help.png", TargetType = typeof(HelpPage(false)) });  //showing syntax errors for this line
我的问题是将我的内容页添加到列表时。以上代码工作正常:

public partial class NavigationDrawerPage : MasterDetailPage
    {
public List<MasterPageItem> menuList { get; set; }
        public MainPage()
        {
            InitializeComponent();

            menuList = new List<MasterPageItem>();

            // Adding menu items to menuList and you can define title ,page and icon
            menuList.Add(new MasterPageItem() { Title = "Home", Icon = "home.png", TargetType = typeof(HomePage) });
            menuList.Add(new MasterPageItem() { Title = "Setting", Icon = "setting.png", TargetType = typeof(SettingPage) });
            menuList.Add(new MasterPageItem() { Title = "LogOut", Icon = "logout.png", TargetType = typeof(LogoutPage) });

            navigationDrawerList.ItemsSource = menuList;

            Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(HomePage)));
        }
}
menuList.Add(new MasterPageItem() { Title = "Home", Icon = "home.png", TargetType = typeof(SettingPage) });
menuList.Add(new MasterPageItem() { Title = "Help", Icon = "help.png", TargetType = typeof(HelpPage(false)) });  //showing syntax errors for this line
但是我有一个只有一个参数的页面,我无法将该参数添加到
TargetType
中。请参阅以下代码:

public partial class NavigationDrawerPage : MasterDetailPage
    {
public List<MasterPageItem> menuList { get; set; }
        public MainPage()
        {
            InitializeComponent();

            menuList = new List<MasterPageItem>();

            // Adding menu items to menuList and you can define title ,page and icon
            menuList.Add(new MasterPageItem() { Title = "Home", Icon = "home.png", TargetType = typeof(HomePage) });
            menuList.Add(new MasterPageItem() { Title = "Setting", Icon = "setting.png", TargetType = typeof(SettingPage) });
            menuList.Add(new MasterPageItem() { Title = "LogOut", Icon = "logout.png", TargetType = typeof(LogoutPage) });

            navigationDrawerList.ItemsSource = menuList;

            Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(HomePage)));
        }
}
menuList.Add(new MasterPageItem() { Title = "Home", Icon = "home.png", TargetType = typeof(SettingPage) });
menuList.Add(new MasterPageItem() { Title = "Help", Icon = "help.png", TargetType = typeof(HelpPage(false)) });  //showing syntax errors for this line

如何将包含参数的内容页添加到列表项中?我是否应该更改
TargetType
datatype

您可以使用方法
公共静态对象CreateInstance(Type Type,params object[]args)传递参数

项目 母版页 添加具有相应参数的构造函数
我假设您正在使用
TargetType
实例化详细信息页面。您可以将具有默认值的
字典
添加到
MasterPageItem
,并在创建详细信息后传递它们instance@shanranm你能分享一个样品吗?