Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Switching TabbedPage views depending on platform

arturmullerarturmuller Member ✭✭✭

I posted this on SO without any answers so thinking here might get an answer. Due to design differences in my app pages, I need to show one of the tab pages depending if its running on Android or iOS. I am trying to do like this below but it is not working, it seems to compile but the app crashes immediately. This is what I tried:

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

What is the way to do this?

Thank you

Best Answer

  • ColeXColeX Member, Xamarin Team Xamurai
    edited March 30 Accepted Answer

    NavigationPage inherits from Page , so modify your code

    <OnPlatform x:TypeArguments="Page">     //here it should be page not 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>
    

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited March 30 Accepted Answer

    NavigationPage inherits from Page , so modify your code

    <OnPlatform x:TypeArguments="Page">     //here it should be page not 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>
    
  • ColeXColeX Member, Xamarin Team Xamurai

    Hi , does your problem solve or not ?

Sign In or Register to comment.