【发布时间】:2016-08-10 08:55:15
【问题描述】:
viewmodel, model and code behind
大家好,
在 XAML 的 ListView 中识别 MVVM 模式的数据绑定方面需要帮助。我不知道为什么它不起作用。我在视图上看不到任何数据。我通过调试得到了这个异常。
Xamarin.Forms.Xaml.XamlParseException:位置 8:10。属性内容为空或不是 IEnumerable
感谢您的回答。
XAML
<ViewCell>
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<StackLayout HorizontalOptions="Start" Orientation="Vertical">
<Label Text="{Binding Name}" />
</StackLayout>
<StackLayout HorizontalOptions="End" Orientation="Vertical">
<Label Text="{Binding Information}" />
</StackLayout>
</StackLayout>
</ViewCell>
代码
public partial class PartyStatusPage : ContentPage
{
public PartyStatusPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = new PartyStatusPageViewModel();
}
}
public class PartyStatusPageViewModel
{
public List<PartyStatus> ItemList;
public PartyStatusPageViewModel()
{
ItemList = new List<PartyStatus>();
ItemList.Add(new PartyStatus { Name = "Max", Information = "test" });
}
}
public class PartyStatus
{
public string Name { get; set; }
public string Information { get; set; }
public bool State { get; set; }
}
【问题讨论】:
-
请不要使用屏幕来显示您的代码。在代码标签中发布您的代码。另外,让你的 Source 成为一个属性而不是一个字段
-
抱歉,我是新用户。感谢您的提示。
标签: c# xaml mvvm data-binding xamarin.forms