How to add control only for iOS in grid

spanspan USMember ✭✭

Hi,

I want to add a control only for iOS in grid. can any one give me the example please.

Best Answer

  • NMackayNMackay GB mod
    edited May 2016 Accepted Answer

    @span

                      <ContentView Grid.Row="1" Grid.Column="1">
                            <OnPlatform x:TypeArguments="View">
                                <OnPlatform.iOS>
                                  <custom:CustomDoneEntry
                                       FontSize="16"
                                        HorizontalOptions="FillAndExpand"
                                        HeightRequest="34"
                                        Text="{Binding Contact.Surname}" />
                                </OnPlatform.iOS>
                                <OnPlatform.Android>
                                    <Entry
                                        FontSize="16"
                                        HorizontalOptions="FillAndExpand"
                                        HeightRequest="34"
                                        Text="{Binding Contact.Surname}" />
                                </OnPlatform.Android>
                            </OnPlatform>
                        </ContentView>
    

    Here's a sample where I use a customrenderer for iOS but in Android I just use the standard entry. You can also set the column width to 0 for other platforms too.

                                    <DataTemplate>
                                            <Grid BackgroundColor="#ffffff">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80" />
                                                    <ColumnDefinition>
                                                        <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="0" />
                                                    </ColumnDefinition>
    

Answers

  • ashalvaashalva GEMember ✭✭✭

    @span, you can use Device.OS to get the device OS
    if (Device.OS == TargetPlatform.iOS) { }

  • spanspan USMember ✭✭

    @ashalva - Thanks for quick reply,

    I am looking in xaml, do you have any example?

  • NMackayNMackay GBInsider, University mod
    edited May 2016 Accepted Answer

    @span

                      <ContentView Grid.Row="1" Grid.Column="1">
                            <OnPlatform x:TypeArguments="View">
                                <OnPlatform.iOS>
                                  <custom:CustomDoneEntry
                                       FontSize="16"
                                        HorizontalOptions="FillAndExpand"
                                        HeightRequest="34"
                                        Text="{Binding Contact.Surname}" />
                                </OnPlatform.iOS>
                                <OnPlatform.Android>
                                    <Entry
                                        FontSize="16"
                                        HorizontalOptions="FillAndExpand"
                                        HeightRequest="34"
                                        Text="{Binding Contact.Surname}" />
                                </OnPlatform.Android>
                            </OnPlatform>
                        </ContentView>
    

    Here's a sample where I use a customrenderer for iOS but in Android I just use the standard entry. You can also set the column width to 0 for other platforms too.

                                    <DataTemplate>
                                            <Grid BackgroundColor="#ffffff">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80" />
                                                    <ColumnDefinition>
                                                        <OnPlatform x:TypeArguments="x:Double" iOS="30" Android="0" />
                                                    </ColumnDefinition>
    
Sign In or Register to comment.