Project is being made for an Android device.
I have searched for a while now and can't find an answer to why this happens.
<ListView x:Name="ScorebdList"
Grid.Row="0"
Grid.ColumnSpan="3"
Grid.RowSpan="4"
SelectionMode="None"
Header="HIGHSCORES">
<ListView.ItemTemplate>
<DataTemplate >
<ViewCell>
<ViewCell.View>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<Label Text="{Binding Score}" HeightRequest="50"
MinimumHeightRequest="50" WidthRequest="50"
MinimumWidthRequest="50" HorizontalTextAlignment="Center"
BackgroundColor="Red"/>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Explanation:
Here I am trying to set the height and width of the Label and same for Grid.
Red background on label to see where it goes.
This is not showing Label at all.
If I were to do this:
<ListView x:Name="ScorebdList"
Grid.Row="0"
Grid.ColumnSpan="3"
Grid.RowSpan="4"
SelectionMode="None"
Header="HIGHSCORES"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate >
<ViewCell>
<ViewCell.View>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding Score}" HorizontalTextAlignment="Center"
BackgroundColor="Red"/>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I added HasUnevenRows attribute and set size and width in grid to auto. Also removed height/width requests of Label.
Now the Label will show, but not as I want it to.
Other things I tested:
I have also tried setting the Label inside a <StackLayout>
instead of Grid with the same results.
(Inside the <ViewCell>
)
Also tried using a <TextCell>
instead of <ViewCell>
, which I could not center but fix the height and width...
Question is:
Why? What am I missing?
Using the second code example is not how I want it to look.
I want my <ListView>
to show highscores in the center of the view with the height and width I set.
(Code below for the images have different colors than above code, Label is #D87040(orange ish) and grid background is #321F1F(Dark red)") Here are two images, first image is with width/height to '*'.