本文介绍了你能与masterdetailpage图标/文本的clickevent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个menupage(即可以作为我的masterdetailpage)和我contentpage一个rootpage。当我点击我想menupage(MDP),当我点击图标/文本初始化它的组成部分我menupage图标/文本。



这可能吗?



这是我目前拥有的代码。

 公共RootPage()
{
NavigationPage.SetHasNavigationBar(这一点,假);
变种theMenu =新MenuPag​​e(本);

theMenu.Title =点击
theMenu.Icon =图标小40.png

//我可以用theMenu.Title点击以上图标?

中间= theMenu;

NavigationPage页=新NavigationPage(新的起始页());
细节=页;

}


解决方案

让我知道下面的代码可以帮助你。

 命名空间LoginNavigation 
{
公共类RootPage:MasterDetailPage
{
menuPag​​e menuPag​​e;
公共RootPage()
{

menuPag​​e =新MenuPag​​e();

menuPag​​e.Menu.ItemSelected + =(发件人,E)=>的NavigateTo(e.SelectedItem为MenuItemForMaster);

中间= menuPag​​e;
细节=新NavigationPage(新的TimeSheet()){
};
}

无效的NavigateTo(MenuItemForMaster菜单)
{
如果(菜单== NULL)
的回报;

页面displayPage =(页)Activator.CreateInstance(menu​​.TargetType);
//细节= displayPage;
细节=新NavigationPage(displayPage){BarBackgroundColor = Color.FromHex(008dce),BackgroundColor中= Color.FromHex(008dce)};

menuPag​​e.Menu.SelectedItem = NULL;
IsPresented = FALSE;
}
}
}

在MenuPag​​e,我有

 菜单=新MenuListView(); 
Menu.RowHeight = 44;
Menu.SeparatorColor = Color.FromHex(e8e8e8);
Menu.SeparatorVisibility = SeparatorVisibility.Default;

menuListView和数据类如下:



 命名空间LoginNavigation 
{
公共类MenuListView:ListView控件
{
公共MenuListView()
{
名单,LT; MenuItemForMaster>数据=新MenuListData();

的ItemsSource =数据;
VerticalOptions = LayoutOptions.FillAndExpand;
BackgroundColor中= Color.Accent;

细胞VAR =新的DataTemplate(typeof运算(MenuCell));
//cell.SetBinding(MenuCell.TextProperty,标题);
//cell.SetBinding(MenuCell.ImageSourcePropertyIconSource);
this.HasUnevenRows = FALSE;
的ItemTemplate =细胞;
}

命名空间LoginNavigation
{
公共类MenuListData:列表< MenuItemForMaster>
{
公共MenuListData()
{
this.Add(新MenuItemForMaster(){
NAME =
的ImageSource =paper_plane.png ,
=的TargetType typeof运算(的TimeSheet)
});
this.Add(新MenuItemForMaster(){
NAME =分机:3969,
=的ImageSource phone_reciever.png,
=的TargetType typeof运算(的TimeSheet)
});
this.Add(新MenuItemForMaster(){
NAME =的TimeSheet,
的ImageSource =Calender.png,
=的TargetType typeof运算(的TimeSheet)
});

this.Add(新MenuItemForMaster(){
NAME =欧米茄 ,
的ImageSource =Notes.png,
=的TargetType typeof运算(欧米茄)
});

}
}
$} b $ b

终于这是MenuItemForMaster

 命名空间LoginNavigation 
{

公共类MenuItemForMaster
{
公共字符串名称{;设置;}

酒店的公共字符串的ImageSource {获取;集;}

公共类型的TargetType {搞定;组; }
}


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 component when I click the icon/text.

Is it possible?

This is the code that I currently have.

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;

    }
解决方案

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

这篇关于你能与masterdetailpage图标/文本的clickevent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 07:12