MAUI - Lines of text not being correctly displayed on IOS Emulators

Riffy 276 Reputation points
2023-02-21T21:47:57.1166667+00:00

Hi All

I having an issue with Lines of text not being correctly displayed on IOS Emulators.

They display fine on Windows Device and Android emulators:

User's image

But for all IOS emulators I get:

enter image description here

The issue occurs on VS Studio for Windows (V 17.4.4) as well as VS for Mac (V 17.5).

Below is an extract of my xaml page extract:

    <RefreshView x:DataType="local:Level2ViewModel" Command="{Binding LoadItemDetailsCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
        <ScrollView VerticalOptions="FillAndExpand"  Padding="7">
            <CollectionView x:Name="ItemsDetailListView" BackgroundColor="{StaticResource PageBckColour}"  
                        ItemsSource="{Binding ItemDets}"   
                        SelectionMode="Single">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <StackLayout  x:DataType="model:ItemDets">
                            <Label Text="{Binding DetDesc}"  Padding="8"
                            LineBreakMode="WordWrap"    
                            TextColor="{StaticResource DescTxtColour}"  FontFamily="OpenSansRegular"
                            FontSize="{x:OnPlatform Android=13, WinUI=14, iOS=13}"                            
                            FontAttributes="Bold" />
                            <StackLayout.GestureRecognizers>
                                <TapGestureRecognizer 
                                NumberOfTapsRequired="1"
                                Command="{Binding Source={RelativeSource AncestorType={x:Type local:Level2ViewModel}}, Path=ItemTapped}"		
                                CommandParameter="{Binding .}">
                                </TapGestureRecognizer>
                            </StackLayout.GestureRecognizers>
                        </StackLayout>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </ScrollView>
    </RefreshView>

Any ideas as how to solve this error would be appreciated.

Thanks

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,448 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,036 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
833 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 49,611 Reputation points Microsoft External Staff
    2023-02-22T05:10:31.1633333+00:00

    Hello,

    The issue that this label text content will exceed the screen length is caused by an error in dynamically allocating the width of the control on iOS for some reason.

    There is a problem in Github similar to the situation you are experiencing, please refer to the workaround from CollectionView inside RefreshView causes layout problems on iOS #11440.

    In my tests, I modified your code to the following and it wrapped normally:

    <RefreshView  >
    <ContentView>
    <CollectionView x:Name="ItemsDetailListView" BackgroundColor="{StaticResource PageBckColour}"  
                            ItemsSource="{Binding players}"  
                            SelectionMode="Single">
    <CollectionView.ItemTemplate>
    <DataTemplate>
    <StackLayout >
    <Label Padding="8" Text="{Binding playerName}" HorizontalTextAlignment="Start" VerticalTextAlignment="Center"
                                LineBreakMode="WordWrap"    
                                TextColor="Blue"  FontFamily="OpenSansRegular"
                                FontSize="{x:OnPlatform Android=13, WinUI=14, iOS=13}"                            
                                FontAttributes="Bold" />
    </StackLayout>
    </DataTemplate>
    </CollectionView.ItemTemplate>
    </CollectionView>
    </ContentView>
    </RefreshView>
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.