WrapLayout miscalculates its layout and presents blank rows or items inside rows where they shouldn't fit

1 Answer 27 Views
WrapLayout
Luis
Top achievements
Rank 1
Luis asked on 09 Apr 2025, 11:07 AM | edited on 09 Apr 2025, 04:15 PM
  • using Telerik 10.1.0, Maui 9.0.50
  • this issue was very obvious when using Windows as resizing the app's window made the layouts render incorrectly at certain sizes
  • reproduced this on Windows, but unsure if the same will apply to other platforms.
  • if the calculations are incorrect across platforms the same issues could happen on Android and iOS if you hit the issue straight away at your device screen size or if you use resizeable windows (which I cannot test myself).
  • I've created a couple of test scenarios, one where the item size (255) is defined via its Width (253) and a Margin (1,1,1,1), and another where the Margin is 0 and the Width is 255.
  • see attached screenshots of app running on my pc (Windows 11 build 10.0.26100.3476)

Repro steps:

  1. Create a blank telerik project (I've not used shell);
  2. Update maui to 9.0.50 (for more relevance with current code);
  3. Replace the contents of MainPage.xaml with the xaml shown below;
  4. Remove unnecessary code from MainPage.xaml.cs to allow app to build and run;
  5. OBSERVE:
    1. Test 1.2 fails - items are shown on a single row when they should not fit.
    2. Test 1.3 fails - items are shown on a single row when they should not fit, and the wrap layout is extended to two rows.
    3. Test 2.1 fails - items are show on two rows when they should fit a single one.

     

 

Xaml to use


    <ContentPage.Resources>
        <ResourceDictionary>
            <Style TargetType="Button">
                <Setter Property="WidthRequest" Value="253" />
                <Setter Property="HeightRequest" Value="77" />
                <Setter Property="Background" Value="Green" />
                <Setter Property="TextColor" Value="White" />
                <Setter Property="Margin" Value="1,1,1,1" />
                <Setter Property="Text" Value="Witdh 253, Margin 1,1,1,1" />
            </Style>

            <Style x:Key="NoMargin" TargetType="Button">
                <Setter Property="WidthRequest" Value="255" />
                <Setter Property="Margin" Value="0" />
                <Setter Property="Text" Value="Witdh 255, Margin 0" />
            </Style>
        </ResourceDictionary>
    </ContentPage.Resources>

    <ScrollView>
        <VerticalStackLayout Margin="30,0" VerticalOptions="Center">
            <!--  FIRST TEST  -->
            <Label Margin="30" HorizontalOptions="Center" Text="The layout below at width 765 should fit all its items on a single row" />
            <telerik:RadWrapLayout Background="DarkGreen" StretchLastChild="False" WidthRequest="765">
                <Button />
                <Button />
                <Button />
            </telerik:RadWrapLayout>
            <Label Margin="30" HorizontalOptions="Center" Text="The layout below at width 764.5 shows items in a single row (when they shouldn't fit)" />
            <telerik:RadWrapLayout Background="DarkRed" StretchLastChild="False" WidthRequest="764.5">
                <Button />
                <Button />
                <Button />
            </telerik:RadWrapLayout>
            <Label Margin="30" HorizontalOptions="Center" Text="The layout below at width 764.4 shows items in a single row (when they shouldn't fit) and presents a blank row" />
            <telerik:RadWrapLayout Background="DarkRed" StretchLastChild="False" WidthRequest="764.4">
                <Button />
                <Button />
                <Button />
            </telerik:RadWrapLayout>
            <Label Margin="30" HorizontalOptions="Center" Text="The layout below at width 764.3 shows items in two rows, as expected" />
            <telerik:RadWrapLayout Background="DarkGreen" StretchLastChild="False" WidthRequest="764.3">
                <Button />
                <Button />
                <Button />
            </telerik:RadWrapLayout>

            <!--  SECOND TEST  -->
            <Label Margin="30" HorizontalOptions="Center" Text="Second test" />
            <Label Margin="30" HorizontalOptions="Center" Text="The layout below at width 765 should fit all its items on a single row, but doesn't" />
            <telerik:RadWrapLayout Background="DarkRed" StretchLastChild="False" WidthRequest="765">
                <Button Style="{StaticResource NoMargin}" />
                <Button Style="{StaticResource NoMargin}" />
                <Button Style="{StaticResource NoMargin}" />
            </telerik:RadWrapLayout>
            <Label Margin="30" HorizontalOptions="Center" Text="The layout below at width 764.5 shows items in two rows" />
            <telerik:RadWrapLayout Background="DarkGreen" StretchLastChild="False" WidthRequest="764.5">
                <Button Style="{StaticResource NoMargin}" />
                <Button Style="{StaticResource NoMargin}" />
                <Button Style="{StaticResource NoMargin}" />
            </telerik:RadWrapLayout>
            <Label Margin="30" HorizontalOptions="Center" Text="The layout below at width 764.4 shows items in two rows" />
            <telerik:RadWrapLayout Background="DarkGreen" StretchLastChild="False" WidthRequest="764.4">
                <Button Style="{StaticResource NoMargin}" />
                <Button Style="{StaticResource NoMargin}" />
                <Button Style="{StaticResource NoMargin}" />
            </telerik:RadWrapLayout>
            <Label Margin="30" HorizontalOptions="Center" Text="The layout below at width 764.3 shows items in two rows" />
            <telerik:RadWrapLayout Background="DarkGreen" StretchLastChild="False" WidthRequest="764.3">
                <Button Style="{StaticResource NoMargin}" />
                <Button Style="{StaticResource NoMargin}" />
                <Button Style="{StaticResource NoMargin}" />
            </telerik:RadWrapLayout>
        </VerticalStackLayout>
    </ScrollView>

 

 

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 14 Apr 2025, 06:47 AM

Hi Luis,

Thank you for the provided details.

I tested the scenario using MAUI 9.0.14 and 9.0.50 and same behavior.  It seems there is a difference when 0.5 pixels need to be measured. I have attached images of the result on my side on windows. 

However, I logged this behavior so the team can review the wrap layout measure in this case. You can track the bug progress at the following link: https://feedback.telerik.com/maui/1684684-wraplayout-the-layout-is-miscalculated-and-blank-row-is-added-when-items-cannot-fit 

I hope this won't be a stopper from using the control.

Regards,
Didi
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Tags
WrapLayout
Asked by
Luis
Top achievements
Rank 1
Answers by
Didi
Telerik team
Share this question
or