Reputation: 2412
I have a Label
inside a StackLayout
inside a Frame
:
<Frame Grid.Row="0" Margin="0, 0, -10, 0" OutlineColor="Transparent" HasShadow="False" Grid.Column="1" BackgroundColor="{StaticResource rightBubbleColor}">
<StackLayout>
<Label
Style="{StaticResource rightBubbleStyle}"
TextColor="{StaticResource rightBubbleFontColor}"
Text="{Binding message}" />
</StackLayout>
</Frame>
This gives me this result:
The problem here is that the last message actually has more text which would need 6 rows to display the whole text.
If I set a value for HeightRequest
for the Label
, it changes the height of the Frame
as well. For example if I set a value of 150, I get this result:
I need to dynamically set a value for HeightRequest
depending on how much height the Text
needs.
Does anyone know how I can achieve that (preferably in xaml) or is this even a wrong approach to my problem?
Removing the style from the Label
doesn't solve the problem. It only occurs on UWP. Note that I don't have a Windows Phone to test it, the problem occurs on my local machine (Windows 10 Desktop).
According to the Xamarin documentation, the height should be autosized dependon on the content:
When the app developer sets the ListView.HasUnevenRows property to true, the behavior of the list view still depends on the ListView.RowHeight property. First, if the developer either does not set the ListView.RowHeight property or sets it to -1, list view items are autosized to fit their contents. This is the desired behavior and the intended use case for a ListView.HasUnevenRows value of true, as noted above.
Upvotes: 3
Views: 3860
Reputation: 2412
I found a solution. This was the problem:
<RowDefinition Height="*" />
I set the value to Auto
and now it's working. Strange that it has a different behaviour on iOS and Android tho.
Upvotes: 2