Can you make a clickevent with the masterdetailpage icon/text?

前端 未结 1 1071
别跟我提以往
别跟我提以往 2021-01-26 04:00

i have a rootpage with a menupage (that works as my masterdetailpage) and my contentpage. when I click my menupage icon/text i want the menupage (mdp) to initialize its componen

相关标签:
1条回答
  • 2021-01-26 04:19

    Let me know if below code helps you

    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;
    }
    }
    }
    

    in MenuPage , i have

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

    menuListView and DataClass is as follows

    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)
    });
    
    }
    }
    }
    

    finally this is MenuItemForMaster

     namespace LoginNavigation
        {
    
        public class MenuItemForMaster
        {
        public string Name { get; set; }
    
        public string ImageSource { get; set; }
    
        public Type TargetType { get; set; }
        }
    
    0 讨论(0)
提交回复
热议问题