PEK
PEK

Reputation: 4328

Smallest possible Label inside a Grid with line breaks

I have a Label inside a Grid. I want:

This is what I have:

<VerticalStackLayout Spacing="8">
    <Label Text='With HorizontalOptions="Start":' />
        
    <Grid BackgroundColor="#FCC" HorizontalOptions="Start">
        <Label
                Text="This will not wrap."
                MaxLines="2"
                />
    </Grid>

    <Grid BackgroundColor="#FCC" HorizontalOptions="Start">
        <Label
                Text="This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. "
                MaxLines="2"
                />
    </Grid>

    <Label Text='With HorizontalOptions="Fill":' />

    <Grid BackgroundColor="#CFC" HorizontalOptions="Fill">
        <Label
                Text="This wraps, but fills."
                MaxLines="2"
                />
    </Grid>

    <Grid BackgroundColor="#CFC" HorizontalOptions="Fill">
        <Label
                Text="This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills."
                MaxLines="2"
                />
    </Grid>
</VerticalStackLayout>

And this is how it looks:

enter image description here

Upvotes: 1

Views: 930

Answers (1)

Alexandar May - MSFT
Alexandar May - MSFT

Reputation: 10156

In conclusion, this is a known issue that be tracked in this thread:https://github.com/dotnet/maui/issues/10494. As @Shaw suggested, we can replace the Grid with an StackLayout to fix the issue. I'll keep an eye on the thread until this is being totally solved.

Thanks for your feedback and patience!

Upvotes: 1

Related Questions