讓我知道如果下面的代碼可以幫助你
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
我不在,現在從我的電腦,將測試明天,如果它的工作原理! – medvedo