Xamarin Form ContentView not work on IOS

DannykhreetDannykhreet USMember ✭✭
edited January 21 in Xamarin.Forms

I want to use contentview on xamarin form and i set inside the content view stacklayout the code below

    <ContentView>
        <StackLayout>
            <Label Text="Label"/>
            <Button Text="click me"/>
        </StackLayout>
    </ContentView>

the elements inside contentview showed on andorid but on ios did not show any element inside contentview
any one can give me any idea why not work on ios .

thanks

Answers

  • NMackayNMackay GBInsider, University mod
    edited January 21

    @Dannykhreet said:
    I want to use contentview on xamarin form and i set inside the content view stacklayout the code below

        <ContentView>
            <StackLayout>
                <Label Text="Label"/>
                <Button Text="click me"/>
            </StackLayout>
        </ContentView>
    

    the elements inside contentview showed on andorid but on ios did not show any element inside contentview
    any one can give me any idea why not work on ios .

    thanks

    Show the full XAML, for example, is the ContentView hosted in a grid, Stacklayout etc, in iOS, you have to sometimes set the layout options for certain UIElements in Forms

       <Grid>
            <ContentView VerticalOptions="Fill">
                 <StackLayout VerticalOptions="CenterAndExpand">
                     <Label Text="Label"/>
                     <Button Text="click me"/>
                 </StackLayout>
             </ContentView>
       </Grid>
    
  • DannykhreetDannykhreet USMember ✭✭

    @NMackay
    this is the full code on the page ,i set it inside ContentPage

        <StackLayout>
            <ContentView>
                <StackLayout>
                    <Label Text="Label"/>
                    <Button Text="click me"/>
                </StackLayout>
            </ContentView>
        </StackLayout>
    

    should i but the contentview on specific element to make it work on ios ?

  • NMackayNMackay GBInsider, University mod

    @Dannykhreet said:
    @NMackay
    this is the full code on the page ,i set it inside ContentPage

        <StackLayout>
            <ContentView>
                <StackLayout>
                    <Label Text="Label"/>
                    <Button Text="click me"/>
                </StackLayout>
            </ContentView>
        </StackLayout>
    

    should i but the contentview on specific element to make it work on ios ?

    That's overly complex, I'm not sure what your trying to achieve unless your getting around a gesture recognizer bug but that only affects UWP.

  • NMackayNMackay GBInsider, University mod
    edited January 21

    This code renders fine on iOS

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="TabbedRepo.Views.AboutPage"
                 Title="Test">
        <Grid>
            <StackLayout>
                <ContentView>
                    <StackLayout>
                        <Label Text="Label"/>
                        <Button Text="click me"/>
                    </StackLayout>
                </ContentView>
            </StackLayout>
        </Grid>
    </ContentPage>
    
    

  • ColeXColeX Member, Xamarin Team Xamurai

    @Dannykhreet Your code looks no problem , could you provide a basic sample which can reproduce this issue ?

  • DannykhreetDannykhreet USMember ✭✭

    @NMackay @ColeX
    Thanks for your replies ,
    the code @NMackay what you suggested work correct but i try to set two Grid inside the stacklayout and choose one of them depends on oriention the full code below inside ContentPage.Content

           `` <StackLayout>
                <ContentView 
                        x:Name="Camera">
                    <StackLayout
                        Spacing="0"
                        Margin="0"
                        Padding="0">
                        <Grid                   
                            IsVisible="False"                 
                            x:Name="MainContainerVertical">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="1*"/>
                                <RowDefinition Height="7*"/>
                                <RowDefinition Height="1*"/>
                                <RowDefinition Height="1.5*"/>
                            </Grid.RowDefinitions>
                            <Image
                                 Grid.Row="0"
                                 Source="close_camera_icon"
                                 x:Name="closePageVertical"
                                 Margin="20,20,0,0"
                                 WidthRequest="30"
                                 HeightRequest="30"
                                 VerticalOptions="Start"
                                 HorizontalOptions="Start"/>
                        </Grid>
    
                        <Grid                  
                            IsVisible="False"
                            x:Name="MainContainerHorizontal">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="7*"/>
                                <ColumnDefinition Width="1.5*"/>
                            </Grid.ColumnDefinitions>
                            <Image
                          Grid.Column="0"
                          Source="close_camera_icon"
                          x:Name="closePageHorizontal"
                          Margin="20,20,0,0"
                          WidthRequest="30"
                          HeightRequest="30"
                          VerticalOptions="Start"
                          HorizontalOptions="Start"/>
                        </Grid>
                    </StackLayout>
                </ContentView>
            </StackLayout>``
    

    thanks

Sign In or Register to comment.