Search code examples
.netformsxamarinmaui

Words Not Wrapping?


I have currently set the following properties to a button, and I want it to word wrap. I want the text to fit inside the button dynamically and not run off the button but it's still running off the button... any ideas?

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="quiz_app.Views.StudyPage"
             Title="Study">
    <StackLayout BackgroundColor="White"
                 Padding="100"
                 HorizontalOptions="CenterAndExpand"
                 VerticalOptions="CenterAndExpand">
        <VerticalStackLayout>
            <Button
                 Text="How much wood could a woodchuck chuck if a woodchuck could chuck wood?"
                 FontSize="40"
                 TextColor="Black"
                 FontFamily="Helvetica"
                 BackgroundColor="#CCFFCC"
                 VerticalOptions="CenterAndExpand" 
                 HorizontalOptions="CenterAndExpand"
                 BorderWidth="5"
                 HeightRequest="400"
                 BorderColor="#82D682"
                 LineBreakMode='WordWrap'>
            </Button>
        </VerticalStackLayout>
    </StackLayout>
</ContentPage>

Solution

  • Thank you @ewerspej for the alternative but I could not get the GestureRecognizer to work for some reason it wasn't recognizing it as a member so I just wrapped a label inside of a border and that did what I wanted to do.

    Edited code below:

    <Border>
        <Label
            Text="How much wood could a woodchuck chuck if a woodchuck could chuck wood?"
            FontSize="40"
            TextColor="Black"
            FontFamily="Helvetica"
            BackgroundColor="#CCFFCC"
            VerticalOptions="CenterAndExpand" 
            HorizontalOptions="CenterAndExpand"
            HeightRequest="400"
            LineBreakMode='WordWrap'>
        </Label>
    </Border>