【发布时间】:2018-01-23 07:00:03
【问题描述】:
正如标题所述,我在 xaml 中的 ListView 绑定有效,但在 c# 中无效。
这里是代码 sn-p: xml
<ListView ItemsSource="{Binding Records}">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding}">
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
C#
ListView lv = new ListView();
lv.ItemsSource = ClassVMInstance.Records;
var dt = new DataTemplate(typeof(TextCell));
dt.SetBinding(TextCell.TextProperty, new Binding("Records"));
lv.ItemTemplate = dt;
ClassVMInstance 是我的 ViewModel 的一个实例。
记录是ObservableCollection<string>
xaml 版本工作正常,它显示文本,但 c# 版本只有空列表元素,没有文本。
(我在同一页面上使用 2 个 listview 一个 xaml 和另一个 c# 进行了测试,只有 xaml 一个显示文本,但 c# 版本只有相同数量的列表项但为空)
我相信 itemssource 属性在代码中正常工作,但绑定不是有人可以帮助我。
【问题讨论】:
标签: c# xaml listview xamarin binding