Xamarin形成边栏

时间:2016-05-08 16:14:36

标签: xamarin xamarin.forms

我已按照以下代码创建了基本的主细节导航:

https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/master-detail-page/

我希望能够在我的侧边栏上创建一个可点击的部分,该部分会将用户带到他们的个人资料页面。与googles侧边栏类似:https://github.com/jamesmontemagno/Xam.NavDrawer

我在哪里可以找到一些如何做到这一点的教程?他们会点击他们的名字/个人资料图片,然后将他们带到他们的个人资料页面。

2 个答案:

答案 0 :(得分:2)

结帐SlideOverKit Xamarin.Forms @

它允许菜单滑出,滑动面板等......从顶部,底部,左侧,右侧......

enter image description here

enter image description here

答案 1 :(得分:2)

以下是在MasterPage中单击图像时导航到其他页面的示例。这是ImageMasterPage的XAML。

<Image
x:Name="profileImage"
HeightRequest="100"
WidthRequest="100"
HorizontalOptions="Center"/>

我们会向TapGestureRecogniser添加Image,然后调用MasterPage中定义的事件。

public partial class MenuPage : ContentPage
{
    public event EventHandler MenuTapped;
    public MenuPage ()
    {
        InitializeComponent ();

        TapGestureRecognizer imageViewTap = new TapGestureRecognizer ();
        imageViewTap.Tapped+= ImageViewTap_Tapped;
        profileImage.GestureRecognizers.Add (imageViewTap);
    }

    async void ImageViewTap_Tapped (object sender, EventArgs e)
    {
        if (MenuTapped != null)
            MenuTapped (this,EventArgs.Empty);
     }
   }

我们可以在MasterPage中收听MasterDetailPage中调用的事件,然后导航到“个人资料”页面。

public class DashboardPage : MasterDetailPage
{
    DetailPage detailPage; 
    MenuPage  masterPage;
    public DashboardPage ()
    {
        detailPage = new DetailPage ();
        var detailNavigationPage=new NavigationPage(detailPage);
        Detail = detailNavigationPage; 
        masterPage= new MenuPage(){Title="Menu",Icon="ic_menuIcon.png"};
        Master = masterPage;
        masterPage.MenuTapped+= MasterPage_MenuTapped;
     }
     async void MasterPage_MenuTapped (object sender, EventArgs e)
     {
         Detail=new new NavigationPage(new ProfilePage());// If you want to load profile page as `DetailPage`
         await Navigation.PushModalAsync(new ProfilePage)// If you want to load profile page as another page modally.
     }