我有一个包含对象的列表。这些对象都有属性。我在后面的代码中遍历这个列表。根据每个项目的特定属性,我决定应该创建什么视图。
那可以是一个按钮、选择器等。此时我已经从服务器到达了 UI。但是现在我需要从 UI 返回到服务器,我认为我需要为此绑定,但我无法完成。我怎样才能做到这一点?
我的代码:
var stack = new StackLayout()
{
Orientation = StackOrientation.Vertical,
Padding = 5
};
for (int i = 0; i < (BindingContext as CheckListEditViewModel).CheckListItems.Count; i++)
{
var item = (BindingContext as CheckListEditViewModel).CheckListItems[i];
var description = new Label();
description.Text = item.Description;
stack.Children.Add(description);
if ((item.ChecklistItemType == Domain.ChecklistItemType.Number))
{
var numerEntry = new Entry();
numerEntry.Keyboard = Keyboard.Numeric;
stack.Children.Add(numerEntry);
}
}
Content = stack;