如何点击导航栏中的barItem将带来新的内容页面

时间:2017-06-11 12:50:09

标签: xamarin.forms

[![在此处输入图像说明] [1]] [1]这是MainPage,其中包含一个包含4个barItems的导航栏。

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             Title="CheckList"
             x:Class="mmy.View.MainPage">    

    <ContentPage.ToolbarItems>
        <ToolbarItem Name="MenuItem1" Order="Primary"  Icon="itemIcon1.png" Priority="0" />
        <ToolbarItem Name="MenuItem2" Order="Primary"  Icon="itemIcon2.png" Priority="1" />
        <ToolbarItem Name="MenuItem1" Order="Primary"  Icon="itemIcon3.png" Priority="2" />
        <ToolbarItem Name="MenuItem2" Order="Primary"  Icon="itemIcon4.png" Priority="3" />

    </ContentPage.ToolbarItems>

    <ContentPage.Content>

        <StackLayout Orientation="Vertical">
            <Label Text="MainPage"/>             
        </StackLayout>        

    </ContentPage.Content>
</ContentPage>


  The Navigation Bar will look like below:

        -------------------------------------------------------
        Main      barItem1  |  barItem2  | barItem3 | barItem4
        -------------------------------------------------------

         Item1_Content

说,导航栏中有4个条形项目

我想做以下事情:

  1. 当用户点击barItem2时,
  2. a)它将引入一个Item2_Content,它将取代Item1_Content。 (我不确定有这样的UI)

    b)barItem(1到4)仍保留在导航栏中。

    这可行吗?

    您能帮我解决一下如何实现这样的用户需求吗?

    由于

    更新 - (1) - 从P1开始:

    private async void BtnLogin_Clicked(object sender, EventArgs e)
    {
      NavigationPage NP = new NavigationPage(new MainPage())
      {
           BarBackgroundColor = Color.White,
           BarTextColor = Color.DarkGray
     };
    }
    

    - (2)我为(3)

    创建了一个新页面调用RepairSvc

    - (3)在MainPage:它有一个导航栏(1)

    单击Icon =&#34; itemIcon1.png&#34;

       <ToolbarItem Name="MenuItem1" Order="Primary"  Icon="itemIcon1.png" Command="Item1Command" Priority="0" />
    
         Code Behind :
    
         [XamlCompilation(XamlCompilationOptions.Compile)]
            public partial class MainPage : ContentPage
            {
               public ICommand Item1Command { get; private set; }
    
                public MainPage()
                {
                   InitializeComponent();
    
                    this.Item1Command = new Command((sender) =>
                    {
                        Navigation.PushAsync(new RepairSvc());
                    });           
                }
    
            }
    

1 个答案:

答案 0 :(得分:0)

将命令分配给工具栏

<ToolbarItem Name="MenuItem1" Order="Primary"  Icon="itemIcon1.png" Priority="0" Command="Item1Command" />
在你的代码隐藏中

   this.Item1Command = new Command((sender) =>
        {
            Navigation.PushAsync(new MyPage());
        });
    }

    public ICommand Item1Command { get; private set; }