【发布时间】:2021-02-18 19:56:31
【问题描述】:
我正在学习 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
【问题讨论】:
-
需要访问才能下载您的代码示例。
-
请在此处添加相关代码。外部链接可能无法访问,或者那里的代码可能会更改,从而使这个问题对未来的读者毫无用处。
标签: c# xamarin mvvm data-binding