【问题标题】:Switching TabbedPage views depending on platform in Xamarin根据 Xamarin 中的平台切换 TabbedPage 视图
【发布时间】:2020-03-28 03:38:28
【问题描述】:

由于我的应用页面的设计差异,我需要显示其中一个标签页,具体取决于它是在 Android 还是 iOS 上运行。我正在尝试在下面这样做,但它不起作用,它似乎可以编译但应用程序立即崩溃。这是我尝试过的:

 <TabbedPage.Children>
        <OnPlatform x:TypeArguments="View">
            <On Platform="Android">
                <NavigationPage Title="{x:Static resources:AppResources.StatsTitle}" IconImageSource="stats1.png">
                    <x:Arguments>
                        <views:StatsPageAndroid />
                    </x:Arguments>
                </NavigationPage>
            </On>
            <On Platform="iOS">
                <NavigationPage Title="{x:Static resources:AppResources.StatsTitle}" IconImageSource="stats2.png">
                    <x:Arguments>
                        <views:StatsPageIos />
                    </x:Arguments>
                </NavigationPage>
            </On>
        </OnPlatform>

        . 
        .
        .
    </TabbedPage.Children>

这样做的方法是什么?

谢谢

【问题讨论】:

    标签: android ios xaml xamarin tabbedpage


    【解决方案1】:

    OnPlatform 类是一个泛型类,必须使用与目标类型匹配的x:TypeArguments 属性进行实例化

    尝试改变

    <OnPlatform x:TypeArguments="View">
    

     <OnPlatform x:TypeArguments="Page">
    

    【讨论】:

      猜你喜欢
      • 2014-01-08
      • 2021-03-21
      • 1970-01-01
      • 2021-03-08
      • 1970-01-01
      • 2020-06-13
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多