Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button only displays first line of multiline text #9949

Closed
KPHIBYE opened this issue Sep 6, 2022 · 5 comments
Closed

Button only displays first line of multiline text #9949

KPHIBYE opened this issue Sep 6, 2022 · 5 comments
Labels
area-controls-button Button, ImageButton platform/android 🤖 t/bug Something isn't working
Milestone

Comments

@KPHIBYE
Copy link

KPHIBYE commented Sep 6, 2022

Description

When trying to set the Text property of a Button to a string that contains line feed (\n) characters, only the text before the first one will be shown in the Button. In Xamarin.Forms, the Button was able to display multiline strings.

Button displaying "Line\nbreak\ntext" in MAUI on Android, first Button has no HeightRequest and second Button has an explicit HeightRequest of 100:
OnlyFirstLineInButton

The expected behavior would be the same as in Xamarin.Forms, that being that the Button tries to display as much of the multiline text horizontally and vertically centered as the Buttons size allows.

Button displaying "Line\nbreak\ntext" in Xamarin.Forms, first Button has no HeightRequest and second Button has an explicit HeightRequest of 100:
OnlyFirstLineInButton_Xamarin

On Windows, the Button behaves as expected and even requests more height if the text doesn't fit.

Button displaying "Line\nbreak\ntext\nlets\ncontinue\nthis\nsome\nmore" in MAUI on Windows, first Button has no HeightRequest and second Button has an explicit HeightRequest of 100:
OnlyFirstLineInButton_Windows

Steps to Reproduce

Try to set a string containing Environment.NewLine or \n as text for a Button on Android

Link to public reproduction project repository

https://github.com/KPHIBYE/ButtonMultilineDemo

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 5 and up

Did you find any workaround?

No

Relevant log output

No response

@KPHIBYE KPHIBYE added the t/bug Something isn't working label Sep 6, 2022
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Sep 6, 2022
@mattleibow mattleibow added this to the Backlog milestone Sep 6, 2022
@ghost
Copy link

ghost commented Sep 6, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mattleibow
Copy link
Member

Might be related to #7618

@adamjhilton
Copy link

Here's a quick and dirty workaround for the interim. Since MAUI buttons can't have direct content, just put the button in a grid and a label over the top of it. Presses/clicks aren't consumed by the label and work on the button. It's not ideal, but it works.

<Grid Grid.Column="2"> <Button Command="{Binding TicketHistoryCommand}" IsVisible="{Binding AppSingleton.Data.UseSplitScreen}" Style="{StaticResource ExtraDarkBlueButton}" /> <Label Style="{StaticResource ButtonLabel}" Text="Ticket&#x0a;History" /> </Grid>

From StaticResources for the label style:

<Style x:Key="ButtonLabel" TargetType="Label"> <Setter Property="FontFamily" Value="OpenSansRegular" /> <Setter Property="FontSize" Value="24" /> <Setter Property="FontAttributes" Value="Bold" /> <Setter Property="TextColor" Value="Black" /> <Setter Property="HorizontalOptions" Value="Center" /> <Setter Property="HorizontalTextAlignment" Value="Center" /> <Setter Property="VerticalOptions" Value="Center" /> </Style>

image

@hartez
Copy link
Contributor

hartez commented Feb 3, 2023

In .NET MAUI, Button now has a LineBreakMode property. It defaults to LineBreakMode.NoWrap.

If you add LineBreakMode="WordWrap" to your Button, it will behave like you're expecting it to when displaying text with Environment.NewLine characters in it.

@hartez hartez closed this as completed Feb 3, 2023
@adamjhilton
Copy link

Confirmed. The LineBreakMode fixes the issue.

Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 8, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-button Button, ImageButton platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants