在代码中设置导航栏标题和图标

not*_*eal 4 icons navigationbar xamarin.forms tabbedpage

大家好,我正在做一个 Xamarin.Forms 应用程序,你可以看到这是我的应用程序:

底部条形页面

在此屏幕截图中,您可以看到我的 App.xaml.cs,我在其中上传了一个底部栏页 StartPage()。

public App()
{

            InitializeComponent();

            //MainPage = new Login();

            NavigationPage nav = new NavigationPage(new StartPage());



            Image img = new Image();
            img.Source = "about_us.png";
            Label label = new Label();
            label.Text = "My App";
            label.VerticalTextAlignment = TextAlignment.Center;
            label.TextColor = Color.Black;

            StackLayout stack = new StackLayout();
            stack.Children.Add(img);
            stack.Children.Add(label);


            nav.SetValue(NavigationPage.TitleViewProperty, stack);
            //nav.SetValue(NavigationPage.TitleProperty, stack);
            nav.SetValue(NavigationPage.BarBackgroundColorProperty, Color.FromHex("#D60000"));
            MainPage = nav;


}
Run Code Online (Sandbox Code Playgroud)

正如您在我的第一个屏幕中看到的,在 App() 中,我试图将标题和应用程序图标添加到导航栏,但不起作用,我该怎么做才能添加它?

Leo*_*SFT 5

从 Xamarin.Forms 3.2.0 开始,您可以在 StartPage.xaml 中放置以下布局:

<NavigationPage.TitleView>
    <StackLayout Orientation="Horizontal" BackgroundColor="#D60000">
        <Image Source="about_us.png" />
        <Label Text="My App" VerticalTextAlignment="Center"/>
    </StackLayout>
</NavigationPage.TitleView>
Run Code Online (Sandbox Code Playgroud)