Is there a way to specify multiple LayoutFlags in XAML Xamarin?
Asked Answered
G

1

9

I Have a label set to relative positioning and auto size as shown below

<Style TargetType="Label">
    <Setter Property="BackgroundColor" Value="Transparent" />
    //Something like below?            
    <Setter Property="AbsoluteLayout.LayoutFlags" Value="PositionProportional | SizeProportional" />
</Style>

....

<Label Text="0" AbsoluteLayout.LayoutBounds="0.5, 0.00499999999999998, AutoSize, AutoSize"/>

Is there a way to specify multiple LayoutFlags in XAML?

As I run the code on devices with higher resolution the relative position of the label is correct but the size (font) of the label does not increase, although it is set to AutoSize. I figured I also needed to specify a LayoutFlag for the Label that is SizeProportional as well as PositionProportional. But how to do it in XAML? Currently the fonts don't resize when the device is rotated to landscape orientation.

Girder answered 20/2, 2017 at 20:11 Comment(0)
K
18

As you can read here : AbsoluteLayout on Xamarin Documentation

Flags are also specified in the declaration of views in the layout using the AbsoluteLayout.LayoutFlags property. Note that flags can be combined in XAML using a comma-separated list.

So in your case, there is no point since you want to use the All value (using both Positionning and Sizing proportionnaly). But I had to use something like this and it works just fine :

<StackLayout AbsoluteLayout.LayoutBounds="0,1,1,100"
                 AbsoluteLayout.LayoutFlags="XProportional,YProportional,WidthProportional">
</StackLayout>

Hope it will help people like who googled it and found this post :)

Krasnoyarsk answered 27/3, 2017 at 22:16 Comment(1)
Note that visual studio shows its correct, but you have to type yourself. Using the autocompletion feature will just replace existing flags.Handmade

© 2022 - 2024 — McMap. All rights reserved.