【问题标题】:Why Toolbar not showing on iOS display using Xamarin为什么使用 Xamarin 在 iOS 显示器上不显示工具栏
【发布时间】:2021-01-27 12:01:02
【问题描述】:

我想在 iOS 上使用 xamarin 显示非常简单的工具栏,但我看不到显示的工具栏。

我使用这个代码:

    <?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>

代码没有错误,显示为空..

需要改变什么才能看到工具栏?

【问题讨论】:

  • 您如何导航到此主页?可以贴一下导航代码吗?
  • 如果您是从 App.xaml.cs 导航,如 Application.Current.MainPage =new MainPage();,则将其更改为 Application.Current.MainPage = new NavigationPage(new MainPage()) ;
  • 我没有导航代码我可以得到明确的文档吗?
  • 如何从 App.xaml.cs 导航到 MainPage?

标签: c# ios xamarin toolbar


【解决方案1】:

您是否将您的页面放在 NavigationPage 中?默认情况下 ContentPage 没有导航栏(工具栏),您必须将页面放在 NavigationPage 中,然后导航栏将显示其功能。 看看这里:Xamarin.Forms Navigation

所以我认为你应该这样做

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-21
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    • 2018-05-03
    • 2012-03-05
    • 1970-01-01
    相关资源
    最近更新 更多