首页 > 解决方案 > 我的面向 Xamarin 的 UWP 应用缺少选项卡

问题描述

我创建了一个简单的 Xamarin 应用程序,其中包含两个页面,每个页面都可以通过选项卡访问,如下所示:

在此处输入图像描述

Android 目标工作正常(如上面的屏幕截图所示),所以我现在添加了一个 UWP 目标。问题是 UWP 目标仅显示一页,即没有选项卡,因此无法在两页之间进行选项卡。

如何将选项卡添加到 UWP 应用?请注意,我在创建 UWP 应用程序时使用了选项卡模板。

其他一切都按预期工作(选项卡除外)。

我正在使用 Visual Studio 2017。

这是主页的 XAML:

<ContentPage.ToolbarItems>
    <ToolbarItem
    Command="{Binding SettingsCommand}"
    Text="Settings">
        <ToolbarItem.Icon>
            <OnPlatform x:TypeArguments="FileImageSource">
                <On Platform="iOS, Android" Value="app_settings" />
                <On Platform="UWP, WinRT, WinPhone" Value="Assets/app_settings.png" />
            </OnPlatform>
        </ToolbarItem.Icon>
    </ToolbarItem>
</ContentPage.ToolbarItems>

<TabbedPage.Title>
    <OnPlatform x:TypeArguments="x:String">
        <On Platform="iOS, UWP, WinRT, WinPhone" Value="MyNamespace" />
    </OnPlatform>
</TabbedPage.Title>

<views:TestEnquiriesView
  x:Name="TestView">
    <views:TestEnquiriesView.Title>Test</views:TestEnquiriesView.Title>
</views:TestEnquiriesView>

<views:ProfileView
  x:Name="ProfileView">
    <views:ProfileView.Icon>
        <OnPlatform x:TypeArguments="FileImageSource">
            <On Platform="iOS, Android" Value="menu_profile" />
            <On Platform="UWP, WinRT, WinPhone" Value="Assets\menu_profile.png" />
        </OnPlatform>
    </views:ProfileView.Icon>
</views:ProfileView>

标签: c#visual-studioxamlxamarinuwp

解决方案


您可以尝试在 的子元素上添加 Title 属性TabbedPage。在 UWP 中,TabbedPage识别Title子元素的属性并将其用作选项卡的显示文本。

此行为与 Android 不同。Android 中设置的图标无法在 UWP 中显示为显示文本。

这是TabbedPage 文档

最好的祝福。


推荐阅读