I've downloaded a XAML sample of a demo that Xamarin provided of a ListView displaying a determined class (NamedColor). I've adapted that code and now I would like to have my label (which is inside the AbsoluteLayout) using a binding. I am currently using AbsoluteLayout.LayoutBounds="0,10,50,50" which fits my android but I would really like to have something like AbsoluteLayout.LayoutBounds="0,(rowHeight-boxSize)/2, boxSize ,boxSize". I previously tried not using the absoluteLayout and added the following properties xAlign="Center", yAlign="Center", WidthRequest="{StaticResource boxSize}", HeightRequest="{StaticResource boxSize}" but in some Cells the label couldn't stay with the height requested, so I decided to use the AbsoluteLayout.
My code:
(...)
<ContentPage.Resources>
<!-- This is only an issue on the iPhone; Android and
WinPhone auto size the row height to the contents. -->
<OnPlatform x:Key="rowHeight"
x:TypeArguments="x:Int32"
iOS="80"
Android="80"
WinPhone="105" />
</ResourceDictionary>
</ContentPage.Resources>
<ListView.ItemTemplate>
<ViewCell.View>
<AbsoluteLayout>
<Label Text="{Binding Class}"
AbsoluteLayout.LayoutBounds="0,10,50,50"
Font="Bold, Large" TextColor="Black
BackgroundColor="{Binding Color}"
</AbsoluteLayout>
<StackLayout Padding="5, 0, 0, 0" VerticalOptions="Center">
<Label Text="{Binding Name}" Font="Bold, Medium" />
<StackLayout Orientation="Horizontal" Spacing="0">
<Label Text="{Binding dateTime}"/>
</StackLayout>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
(...)
Previous label code:
<Label Text="{Binding Class}"
Font="Bold, Large" TextColor="Black"
BackgroundColor="{Binding Color}"
WidthRequest="{StaticResource boxSize}"
HeightRequest="{StaticResource boxSize}"
XAlign="Center"
YAlign="Center"/>
There is a image file attached with the ouput of the AbsoluteLayout vs WitdthRequest&HeightRequest.
Thanks in advance