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

Xamarin.forms 在代码中设置导航栏标题和图标,xamarin.forms,icons,navigationbar,tabbedpage,Xamarin.forms,Icons,Navigationbar,Tabbedpage,嘿,伙计们,我正在做一个Xamarin.Forms应用程序,你们可以看到这是我现在的应用程序: 在这个屏幕截图中,您可以看到我的App.xaml.cs,其中我上载了StartPage(),这是一个底部BarPage public App() { InitializeComponent(); //MainPage = new Login(); NavigationPage nav = new NavigationPag

嘿,伙计们,我正在做一个Xamarin.Forms应用程序,你们可以看到这是我现在的应用程序:

在这个屏幕截图中,您可以看到我的App.xaml.cs,其中我上载了StartPage(),这是一个底部BarPage

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;


}

正如您在我的第一个屏幕中所看到的,在App()中,我试图向导航栏添加标题和App图标,但不起作用,我应该如何添加它?

由于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>


Hi,不要发布代码图像,而是粘贴代码并将其包装在
code
标签上。您不应该在应用程序类上编写ui逻辑。@FabriBertani我应该如何自定义栏,添加图标和标题?您的意思是要同时将标题和图标放在导航栏中?您使用的是什么版本的XF?