微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Xamarin WPF 中使用 TabbedPage 更新 #1:我尝试构建 GTK 目标,它工作正常:

如何解决如何在 Xamarin WPF 中使用 TabbedPage 更新 #1:我尝试构建 GTK 目标,它工作正常:

我正在尝试使用 Xamarin Forms 重建我的旧 WinForms 应用程序以提高可移植性。

应用程序使用 TabControlthe docs 表示最接近的 Xamarin Forms 元素是 TabbedPage

代码如下:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MyApp"
            x:Class="MyApp.MainPage">
    <TabbedPage.toolbaritems>
        <ToolbarItem Text="Settings"
                     Order="Primary"
                     Priority="0" />
        <ToolbarItem Text="Tools"
                     Order="Primary"
                     Priority="1" />
        <ToolbarItem Text="Help"
                     Order="Primary"
                     Priority="2" />
    </TabbedPage.toolbaritems>

    <TabbedPage.Children>
        <ContentPage Title="Main">
            <Label Text="Coming soon!"/>
        </ContentPage>

        <ContentPage Title="Today">
            <Label Text="Coming soon!"/>
        </ContentPage>

        <ContentPage Title="This week">
            <Label Text="Coming soon!"/>
        </ContentPage>

    </TabbedPage.Children>

</TabbedPage>

它在我的 UWP 版本上运行良好:

enter image description here

但是,在我的 WPF 版本中,它不显示工具栏,因此无法切换选项卡:

enter image description here

那么我在这里做错了什么?

谢谢。

更新 #1:我尝试构建 GTK 目标,它工作正常:

enter image description here

此屏幕截图是在 Ubuntu 上拍摄的。 Windows 上的 GTK# 工作方式相同,但控件的绘制有问题。

解决方法

弄乱工具栏中的元素选择器后,我终于找到了答案:

WPF 中有用于在选项卡之间切换的按钮。但是,它们只是不可见:enter image description here

BarTextColor 中设置 TabbedPage 属性可解决此问题: enter image description here

所以得到的代码是:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:TimetableApp"
            x:Class="TimetableApp.MainPage" 
            BarTextColor="Black">
    <TabbedPage.ToolbarItems>
        <ToolbarItem Text="Settings"
                     Order="Primary"
                     Priority="0" />
        <ToolbarItem Text="Tools"
                     Order="Primary"
                     Priority="1" />
        <ToolbarItem Text="Help"
                     Order="Primary"
                     Priority="2" />
    </TabbedPage.ToolbarItems>

    <TabbedPage.Children>
        <ContentPage Title="Main">
            <Label Text="Coming soon!"/>
        </ContentPage>

        <ContentPage Title="Today">
            <Label Text="Coming soon!"/>
        </ContentPage>

        <ContentPage Title="This week">
            <Label Text="Coming soon!"/>
        </ContentPage>

    </TabbedPage.Children>

</TabbedPage>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。