如何将TitleIcon和按钮添加到NavigationPage的导航栏?

时间:2016-11-28 10:22:33

标签: xamarin navigation xamarin.forms cross-platform navigationbar

我正在尝试将TitleIcon和重新加载按钮添加到NavigationPage的导航栏,但不知道该怎么做。我试图使用Icon属性导航页面,但它不起作用。关于向导航页添加按钮我还没有找到任何东西。

<?xml version="1.0" encoding="UTF-8"?>
      <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" 
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                x:Class="App.MasterDetailMenu"
                xmlns:local="clr-namespace:App;assembly=App">
    <MasterDetailPage.Master>

          <local:MasterPage/>

    </MasterDetailPage.Master>

   <MasterDetailPage.Detail >

    <NavigationPage BarBackgroundColor="#7FBE5D" x:Name="NavBar" Icon="image.png">


        <x:Arguments>
            <local:Feedbacks/>
        </x:Arguments>
    </NavigationPage>
</MasterDetailPage.Detail>

1 个答案:

答案 0 :(得分:2)

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class AboutPage : ContentPage
{
    public AboutPage()
    {
        InitializeComponent();
        NavigationCommand = new Command(NavigationCommandToInfo);
        ToolbarItems.Add(new ToolbarItem() { Icon = "Info2.png", Command=NavigationCommand });
    }

    public ICommand NavigationCommand { get; }

    void NavigationCommandToInfo() =>
        Navigation.PushAsync(new MainPage());
}