简体   繁体   中英

Why Toolbar not showing on iOS display using Xamarin

I want to display very simple Toolbar using xamarin on iOS, but I can't see the toolbar on display.

I use this code:

    <?xml version="1.0" encoding="utf-8" ?>
      <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                   x:Class="Test.MainPage">

        <ContentPage.ToolbarItems>
          <ToolbarItem Text="Example Item"
                       IconImageSource="https://img.icons8.com/cute-clipart/64/000000/menu.png"
                     Order="Primary"
                     Priority="0" />
        </ContentPage.ToolbarItems>

</ContentPage>

There are no errors in the code and the display is empty..

What needs to change to see the toolbar?

Are you putting your page in NavigationPage? By default ContentPage does not have Navigation bar (Toolbar), you must put your page in NavigationPage, after that Navigation bar will show up with its functionality. have a look at here: Xamarin.Forms Navigation

So I assume you should do something like this

public App ()
{
   MainPage = new NavigationPage (new MainPage());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM