Reputation: 1636
I am trying to put a label inside stacklayout... The number of lines can change depending on data... But when text is more label is going out of view, its not expanding..
<StackLayout Orientation="Vertical"
BackgroundColor="White"
VerticalOptions="FillAndExpand"
Spacing="0">
<StackLayout Orientation="Vertical" BackgroundColor="Silver"
HeightRequest="45">
<AbsoluteLayout BackgroundColor="White"
HorizontalOptions="FillAndExpand"
HeightRequest="44"
Margin="0.5"
VerticalOptions="StartAndExpand"
>
<Label Text="Objective"
Margin="15,0,0,0"
AbsoluteLayout.LayoutBounds="0,0.5,-1,-1"
AbsoluteLayout.LayoutFlags="PositionProportional"
VerticalTextAlignment="Center"
FontFamily="Roboto#300" FontSize="16" FontAttributes="None" TextColor="#FF888888" />
<Button HeightRequest="32" Margin="0,0,15,0"
WidthRequest="32"
Padding="0"
x:Name="ObjectiveButton"
Clicked="Objective_Button_Handle_Clicked"
BackgroundColor="Transparent"
AbsoluteLayout.LayoutBounds="1,0.5,-1,-1"
AbsoluteLayout.LayoutFlags="PositionProportional"
Image="collapseIcon.png"/>
</AbsoluteLayout>
</StackLayout>
<StackLayout Orientation="Vertical"
BackgroundColor="White"
x:Name="ObjectiveStackLayout"
VerticalOptions="CenterAndExpand"
IsVisible="true" >
<Label Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
Ut enim ad minim veniam,
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea
commodo consequat."
FontFamily="Roboto#400"
FontSize="14"
VerticalTextAlignment="Center"
Margin="15,10,0,0"
MaxLines="0"
LineBreakMode="WordWrap"
FontAttributes="None"
TextColor="#FF858585" />
</StackLayout>
</StackLayout>
Upvotes: 0
Views: 846
Reputation: 1636
So Finally I solved this using Grid... Instead of taking root view as StackLayout, I took it as Grid. If we set Auto property for row height.. Label size is getting determined on the basis of its content.
Upvotes: 1
Reputation: 236
What you are asking is the default behavior of a label inside a stacklayout, providing you let it.
I don't get what you are trying to do with MaxLines, here you are asking 0 line of text to show in your label, nothing should be displayed at all.
You just need to get rid of the MaxLines property, so the label can adjust depending on it's content by itself.
Either that, or I didn't get what you are trying to do.
Upvotes: 0