.net 单词不换行?

ou6hu8tu  于 2022-12-14  发布在  .NET
关注(0)|答案(2)|浏览(145)

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>
4ngedf3f

4ngedf3f1#

Just for completeness sake:
A possible solution using a TapGestureRecognizer could look as follows:

<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.GestureRecognizers>
        <TapGestureRecognizer Command="{Binding SomeCommand}" />
    </Label.GestureRecognizers>
<Label>
yhxst69z

yhxst69z2#

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>

相关问题