你能用masterdetailpage图标/文字制作一个clickevent吗?

我有一个带有menupage的rootpage(作为我的masterdetailpage)和我的内容页面。 当我单击我的menupage图标/文本时,我希望menupage(mdp)在单击图标/文本时初始化其组件。

可能吗?

这是我目前拥有的代码。

public RootPage () { NavigationPage.SetHasNavigationBar (this, false); var theMenu = new MenuPage (this); theMenu.Title = "Click"; theMenu.Icon = "Icon-Small-40.png"; //can I make a click with the theMenu.Title or Icon above? Master = theMenu; NavigationPage page = new NavigationPage(new StartPage ()); Detail = page; } 

如果以下代码可以帮助您,请告诉我

 namespace LoginNavigation { public class RootPage:MasterDetailPage { MenuPage menuPage; public RootPage () { menuPage = new MenuPage (); menuPage.Menu.ItemSelected += (sender, e) => NavigateTo (e.SelectedItem as MenuItemForMaster); Master = menuPage; Detail = new NavigationPage (new TimeSheet()){ }; } void NavigateTo (MenuItemForMaster menu) { if (menu == null) return; Page displayPage = (Page)Activator.CreateInstance (menu.TargetType); //Detail = displayPage; Detail = new NavigationPage (displayPage) { BarBackgroundColor = Color.FromHex("008dce"),BackgroundColor = Color.FromHex("008dce")}; menuPage.Menu.SelectedItem = null; IsPresented = false; } } } 

在MenuPage中,我有

 Menu = new MenuListView (); Menu.RowHeight = 44; Menu.SeparatorColor = Color.FromHex ("e8e8e8"); Menu.SeparatorVisibility = SeparatorVisibility.Default; 

menuListView和DataClass如下

 namespace LoginNavigation { public class MenuListView : ListView { public MenuListView () { List data = new MenuListData (); ItemsSource = data; VerticalOptions = LayoutOptions.FillAndExpand; BackgroundColor = Color.Accent; var cell = new DataTemplate (typeof(MenuCell)); //cell.SetBinding (MenuCell.TextProperty, "Title"); //cell.SetBinding (MenuCell.ImageSourceProperty, "IconSource"); this.HasUnevenRows = false; ItemTemplate = cell; } namespace LoginNavigation { public class MenuListData : List { public MenuListData () { this.Add (new MenuItemForMaster () { Name = “" ImageSource = "paper_plane.png", TargetType = typeof(TimeSheet) }); this.Add (new MenuItemForMaster () { Name = "Extn : 3969", ImageSource = "phone_reciever.png", TargetType = typeof(TimeSheet) }); this.Add (new MenuItemForMaster () { Name = "TimeSheet", ImageSource = "Calender.png", TargetType = typeof(TimeSheet) }); this.Add (new MenuItemForMaster () { Name = "Omega", ImageSource = "Notes.png", TargetType = typeof(Omega) }); } } } 

最后这是MenuItemForMaster

  namespace LoginNavigation { public class MenuItemForMaster { public string Name { get; set; } public string ImageSource { get; set; } public Type TargetType { get; set; } }