0
votes

I just created empty xamarin.forms project and nothing in it.

I searched on how to add Toolbar, in Microsoft documentation say add these line to xaml file.

    <ContentPage.ToolbarItems>
    <ToolbarItem Text="Example Item"
                 IconImageSource="example_icon.png"
                 Order="Primary"
                 Priority="0" />
    </ContentPage.ToolbarItems>

But not toolbar is showing on my android device, this is really sad because this is my first time using xamarin and this is just empty project but it is not working.

this is my main xaml file

 <?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="test3.MainPage">
    <ContentPage.ToolbarItems>
        <ToolbarItem Text="sssssssss Item"
                 Order="Primary"
                 Priority="0" />
    </ContentPage.ToolbarItems>
    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
    </StackLayout>
</ContentPage>
1
You need to use a NavigationPage in order for the Toolbar to displayJason

1 Answers

2
votes

Your App.xaml.cs should be similar to this:-

public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new NavigationPage(new test3.MainPage());
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }