下面是.axml,用于显示绑定到名为EventDetailList
的对象列表的MvxListView,每个ItemClick绑定到DoEventDetailCommand
:
EventDetailView.axml
<?xml version="1.0" encoding="utf-8"?>
<Mvx.MvxListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="ItemsSource EventDetailList; ItemClick DoEventDetailCommand"
local:MvxItemTemplate="@layout/event_detailitem" />
单击此列表中的一个项目后,将在ViewModel中调用一个操作,该操作会将另一个EventDetailItem
添加到
。添加此新项目后,它会立即显示在列表中。但是,单击此新添加的项不会执行ObservableCollection EventDetailList<EventDetailItem>
ObservableCollection EventDetailList<EventDetailItem>
。我必须离开屏幕并返回,以便新添加的项目在单击时执行ICommand DoEventDetailCommand
。
EventDetailViewModel.cs
DoEventDetailCommand
private ObservableCollection<EventDetailItem> _eventDetailList;
public ObservableCollection<EventDetailItem> EventDetailList
{
get
{
return _eventDetailList;
}
set
{
_eventDetailList = value;
if(_eventDetailList == null ||
_eventDetailList.Count == 0)
{
Close(this);
}
RaisePropertyChanged(() => EventDetailList);
}
}
...
public ICommand DoEventDetailCommand
{
get
{
return new MvxCommand<EventDetailItem>(item =>
{
switch(item.ItemAction)
{
case EventDetailItem.Action.Information:
break;
case EventDetailItem.Action.DriverSig:
EventDetailList.Add(new EventDetailItem() {
ItemAction = EventDetailItem.Action.Cancel,
IconImageType = EventDetailItem.IconType.Cancel,
Label = "Cancel" });
break;
case EventDetailItem.Action.Cancel:
ShowViewModel<CancelTripViewModel>(new CancelTripViewModel.Nav() {Id=_curId});
break;
....