FlexLayout
(without explicit HeightRequest
) placed inside a Grid
's Row
(Height="Auto"
), the FlexLayout
will be rendered as the same height as the Grid
.
Flexlayout
with explicit `HeightRequest
. Grid render correctly.FlexLayout
with other controls. Grid render correctly.FlexLayout
without explicit HeightRequest
inside a StackLayout
. Render correctly.xml
<Grid x:Name="grid" RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<BoxView Grid.Row="0" BackgroundColor="Red" VerticalOptions="FillAndExpand"/>
<FlexLayout x:Name="flex" Grid.Row="1" BackgroundColor="Yellow">
<Button Text="Check Height" Clicked="CheckHeight_Clicked" HeightRequest="40" />
</FlexLayout>
<BoxView Grid.Row="2" BackgroundColor="Green" VerticalOptions="FillAndExpand"/>
</Grid>
Actual behavior vs Expected behavior
Also tested against the latest 4.0-pre
I believe I'm seeing the same issue on UWP.
I created this (F#) workaround which sort of fixes the issue for me - though it's not perfect, it is bit glitchy when resizing the UWP window.
Something is really wrong with that OnMeasure method in the core implementation of XF.
type FlexLayout_HackFix20190326() =
inherit FlexLayout()
override self.OnMeasure(widthConstraint, heightConstraint) =
let height = self.Children |> Seq.map (fun c -> c.Measure(Double.PositiveInfinity, Double.PositiveInfinity).Request.Height + c.Bounds.Top) |> Seq.maxBy id
base.OnMeasure(widthConstraint, height)
Will this ever be fixed? It basically makes FlexLayout unusable. My "fix" above isn't really good enough - it's too glitchy for production use.
The same for me
Same here. I'm temporary wrapping the FlexLayout inside a StackLayout until this issue is solved.
@DoubleDBE Wrapping StackLayout can help. Also, we can get the same behavior as StackLayout if we override OnMeasure in FlexLayout and change widthConstrain or heigthContrain to double.PositinInfinity. But FlexLayout calculates the size of elements inside incorrectly. For example, when I put Label with long text, Grow = 0.5 and WordWrap inside FlexLayout I got incorrect label height and the text was cut.
Just ran into this issue with a FlexLayout out inside my ViewCell. Wrapping in StackLayout as a work around helped.
Same problem, here is an example where the FlexLayout should be aligned at the beginning at the top but it takes all the space horizontally and vertically.
````xml
HorizontalOptions="Start"
VerticalOptions="Start">
<FlexLayout
AlignContent="Start"
AlignItems="Start"
AlignSelf="Start"
BackgroundColor="Blue"
Direction="Row"
HorizontalOptions="Start"
JustifyContent="Start"
VerticalOptions="Start">
<Label
BackgroundColor="Red"
FlexLayout.Basis="100"
FlexLayout.Grow="0"
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
Text="Content1"
WidthRequest="100" />
<Label
BackgroundColor="Orange"
FlexLayout.Basis="100"
FlexLayout.Grow="0"
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
Text="Content2"
WidthRequest="100" />
</FlexLayout>
</Grid>
````
Can also be reproduced in the official samples (see the Experiment page): https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/FlexLayoutDemos
Same here working with XF4.7, is anybody working on this problem?
Same problem but I'm within an AbsoluteLayout
, maybe related (https://forums.xamarin.com/discussion/184860/problem-with-a-scrollview-having-a-flexlayout-inside-absolutelayout#latest).
It looks as if the extra height added to my ScrollView
is related to the height it would take if the FlexLayout
was a simple StackLayout
and no wrapping would be done with the content.
I tried as suggested to wrap my FlexLayout
into an(other) StackLayout
but it does not help.
@nbevans My mobile app will obviously not "resize" (maybe change orientation but I could possibly live with that). Is your hack somehow to be implemented for both iOS and Android somehow? Custom renderer? Mind providing the code?
Same here. I'm temporarily wrapping the FlexLayout inside a StackLayout until this issue is solved.
Yes, exactly, I am facing this issue yet so I have wrapped FlexLayout with StackLayout, and it works fine.
<StackLayout Grid.Row="0" HorizontalOptions="FillAndExpand" Padding="10" VerticalOptions="Start">
<FlexLayout BackgroundColor="Green" HorizontalOptions="FillAndExpand" VerticalOptions="Start" BindableLayout.ItemsSource="{Binding ItemCollection}"
Direction="Row" Wrap="Wrap" JustifyContent="Start" AlignContent="Start" Margin="0" Padding="0">
<BindableLayout.ItemTemplate>
<DataTemplate>
<pancake:PancakeView BackgroundColor="Blue"
HasShadow="False" IsClippedToBounds="True" Padding="5" Margin="5"
CornerRadius="10" HeightRequest="30" HorizontalOptions="Start" VerticalOptions="Start">
<Label Text="{Binding Title}" TextColor="White" HorizontalOptions="Center"
VerticalOptions="Center" HorizontalTextAlignment="Center"
VerticalTextAlignment="Center" />
</pancake:PancakeView>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
</StackLayout>
FYI: Having placed the Flexlayout inside a Stacklayout which is placed inside two nested Grids triggers a NullReferenceException in LayoutSubviews().. Removing the uppermost Grid resolves this.
Most helpful comment
Same problem, here is an example where the FlexLayout should be aligned at the beginning at the top but it takes all the space horizontally and vertically.
BackgroundColor="Yellow"
````xml
HorizontalOptions="Start"
VerticalOptions="Start">
````