如何解决为什么第三个标签和按钮没有显示在UI中?
我正在学习Xamarin.Forms和MVVM模式,其中包括数据绑定。我不明白为什么在第二个标签之后,什么都没有显示,但是Str_Winner遇到了断点,并且该字符串的内容与我期望的值相同。
Page_History.xaml如下:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local1="clr-namespace:TicTacToe.viewmodel"
x:Class="TicTacToe.View.Page_History">
<ContentPage.Resources>
<ResourceDictionary>
<local1:VM_GameInfo x:Key="VM_GameInfo"/>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout BindingContext="{StaticResource VM_GameInfo}">
<ListView ItemsSource="{Binding GameHistory}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<Label Text="{Binding Str_Title}" />
<Label Text="{Binding SaveDateTime}" />
<Label Text="{Binding Str_Winner}" />
<Button Text="Something"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
我的代码在这里:https://drive.google.com/file/d/1w1TL0am6VeS2dLgsesiQT_S2h0L7Lo1H/view?usp=sharing
解决方法
给RowHeight="150"
或将HasUnevenRows="True"
设置为listView:
<ListView ItemsSource="{Binding GameHistory}" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<Label Text="{Binding Str_Title}" />
<Label Text="{Binding SaveDateTime}" />
<Label Text="{Binding Str_Winner}" />
<Button Text="Something"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。