StackLayout can be expand more than screen now #24515
-
Description
<HorizontalStackLayout>
<Label
LineBreakMode="TailTruncation"
MaxLines="2"
Text="{Binding Text}"
VerticalTextAlignment="Center" />
<Button Text="Edit" />
</HorizontalStackLayout> What I expect is when the Of course if the text always long then I can consider myself to use Steps to Reproduce
Link to public reproduction project repositoryhttps://github.com/albilaga/MauiIssues Version with bug8.0.61 SR6.1 Is this a regression from previous behavior?Yes, this used to work in Xamarin.Forms Last version that worked wellUnknown/Other Affected platformsiOS, Android Affected platform versionsiOS 15, Android Did you find any workaround?Not yet Relevant log outputNo response |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 1 reply
-
Hi I'm an AI powered bot that finds similar issues based off the issue title. Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you! Open similar issues:
Closed similar issues:
|
Beta Was this translation helpful? Give feedback.
-
I can repro this issue at Android platform on the latest 17.11.0 Preview 2.1 (8.0.61). |
Beta Was this translation helpful? Give feedback.
-
This was an intentional change from XF |
Beta Was this translation helpful? Give feedback.
-
@PureWeen then how do I want to achieve text is basically don't want to out of screen but still stacked nicely if it is not too long? <Grid ColumnDefinitions="Auto,*">
<Label
LineBreakMode="TailTruncation"
MaxLines="2"
Text="5. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel sapien ut odio sollicitudin iaculis vel ut tortor. Proin mauris magna, tincidunt a congue vitae, pellentesque ac ligula."
VerticalTextAlignment="Center" />
<Button Grid.Column="1" Text="Edit" />
</Grid> |
Beta Was this translation helpful? Give feedback.
-
@albilaga Your column layout is backwards, it should be "*, Auto". You need the label to take up the full width of the given space within the parent container, and the button to fill only the intrinsic width of the button itself. Setting "Auto" on label is saying that the Label should fill whatever width it has, which is none since that needs to be set by whatever its parent container is. So it'll never wrap and it'll break the other column. That's not a bug in MAUI as far as I know, that's a misconfiguration. |
Beta Was this translation helpful? Give feedback.
-
@drasticactions that's why I add description in my issue
The problem using |
Beta Was this translation helpful? Give feedback.
-
@PureWeen is this the expected behavior now? so this layout is not possible? |
Beta Was this translation helpful? Give feedback.
-
You can use MultiMathExpressionConverter from CommunityToolkit.Maui to solve your problem: <HorizontalStackLayout x:Name="horizontalStackLayout">
<Label
LineBreakMode="TailTruncation"
MaxLines="2"
MaximumWidthRequest="{MultiBinding {Binding Width, Source={Reference horizontalStackLayout}},
{Binding Width, Source={Reference button}},
Converter={StaticResource MultiMathExpressionConverter},
ConverterParameter='x-x1'}"
Text="{Binding Text}"
VerticalTextAlignment="Center" />
<Button x:Name="button" Text="Edit" />
</HorizontalStackLayout> If you wish to eliminate the need to use x:Name in your Binding, you can use RelativeSource Self, e.g. <HorizontalStackLayout>
<Label
LineBreakMode="TailTruncation"
MaxLines="2"
MaximumWidthRequest="{MultiBinding {Binding Parent.Width, Source={RelativeSource Self}},
{Binding Parent[1].Width, Source={RelativeSource Self}},
Converter={StaticResource MultiMathExpressionConverter},
ConverterParameter='x-x1'}"
Text="{Binding Text}"
VerticalTextAlignment="Center" />
<Button Text="Edit" />
</HorizontalStackLayout> |
Beta Was this translation helpful? Give feedback.
You can use MultiMathExpressionConverter from CommunityToolkit.Maui to solve your problem: