2016-04-03 74 views
0

我有一個包含menupage(作爲我的masterdetailpage)和我的內容頁的根頁面。當我點擊我的menupage圖標/文本時,我想讓menupage(mdp)在單擊圖標/文本時初始化其組件。你可以用masterdetailpage圖標/文本製作一個clickevent嗎?

這可能嗎?

這是我目前擁有的代碼。

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; 

    } 

回答

0

讓我知道如果下面的代碼可以幫助你

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和數據類如下

namespace LoginNavigation 
{ 
public class MenuListView : ListView 
{ 
public MenuListView() 
{ 
List<MenuItemForMaster> 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<MenuItemForMaster> 
{ 
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

​​
+0

我不在,現在從我的電腦,將測試明天,如果它的工作原理! – medvedo

相關問題