Xamarin MVVMCross Spinner 在对象中显示名称

Xamarin MVVMCross Spinner Show Name in Object

我正在尝试获取我的参与者列表并在微调器中显示参与者姓名。

参与者对象:

public class Participant
{
public int UserId { get; set; }
public string Name { get; set; }
}

视图模型:

private List _participantFilterList = null;
public List ParticipantFilterList 
{
   get { return _participantFilterList; }
   set {
      _participantFilterList = value;
      RaisePropertyChanged(() => ParticipantFilterList);
   }
}

private Participant _selectedParticipantFilter = null;
public Participant SelectedParticipantFilter
{
    get { return _selectedParticipantFilter; }
    set {
        _selectedParticipantFilter = value;
        RaisePropertyChanged(() => SelectedParticipantFilter);
    }
}

查看:

var respondentSelect = fragView.FindViewById(Resource.Id.respondentSelect);
... 
set.Bind(respondentSelect).For(x => x.ItemsSource).To(vm => vm.ParticipantFilterList);
set.Bind(respondentSelect).For(x => x.SelectedItem).To(vm => vm.SelectedParticipantFilter);

所有这些似乎主要是通过在微调器中向我展示这个来工作的:

虽然我需要它来显示参与者姓名,但我不确定这样做缺少什么。

您需要在绑定实际微调器的 xml 布局文件中添加类似 MvxItemTemplate="@layout/ParticipantItemTemplate" 的声明。还要确保将微调器声明为 MvxSpinner 视图。