我正在努力做些琐碎的事情。
我有这样的MvxGridView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Mvx.MvxGridView
android:id="@+id/subjects_gv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:numColumns="2"
android:verticalSpacing="15dp"
android:gravity="center"
app:MvxItemTemplate="@layout/assigned_subject_view"
app:MvxBind="ItemClick ShowSubjectFeatures;ItemsSource Subjects;"/>
</LinearLayout>
这是模板
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
local:cardUseCompatPadding="true"
local:cardCornerRadius="5dp">
<RelativeLayout
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:orientation="vertical"
android:clickable="true"
android:background="?android:attr/selectableItemBackground">
<ImageView
android:layout_centerInParent="true"
android:id="@+id/iv_subject_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/english" />
<TextView
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"
android:id="@+id/tv_subject_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:gravity="center"
android:maxLines="2"
android:stretchMode="spacingWidthUniform"
android:textSize="@dimen/very_small_text"
local:MvxBind="Text Name" />
</RelativeLayout>
</android.support.v7.widget.CardView>
这是视图模型
private readonly IMvxNavigationService _navigationService;
private readonly ISubjectsService _subjectsService;
public SubjectsViewModel(IMvxNavigationService navigationService, ISubjectsService subjectsService)
{
_navigationService = navigationService;
_subjectsService = subjectsService;
}
public MvxObservableCollection<SubjectModel> Subjects { get; set; } = new MvxObservableCollection<SubjectModel>();
public MvxCommand<SubjectModel> ShowSubjectFeatures
{
get
{
// Navigate to subject details viewmodel
return new MvxCommand<SubjectModel>(async subject => await NavigateToFeatures(subject));
}
}
public override async Task Initialize()
{
var response = await _subjectsService.GetAssignedSubjects();
Subjects.AddRange(response.Subjects);
}
private async Task NavigateToFeatures(SubjectModel model)
{
await _navigationService.Navigate<SubjectFeatureViewModel, int>(model.Id);
}
问题是,当我单击网格项目时,不会触发命令。其他信息,gridview显示在一个片段中,而SubjectFeaureView也是一个片段,因此它将在一个片段之间导航。我认为这不应该成为问题。我想念什么?我对此很陌生。