Xamarin MVVMCross Spinner在Object中显示名称

时间:2015-10-12 16:01:46

标签: c# android xamarin xamarin.android mvvmcross

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

参与者对象:

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);

所有这一切似乎主要是通过在微调器中向我展示这一点: enter image description here

我需要它来向我显示参与者名称,但我不确定我缺少这样做。

1 个答案:

答案 0 :(得分:4)

您需要在axml布局文件中添加类似MvxItemTemplate="@layout/ParticipantItemTemplate"的声明,您可以在其中绑定实际的微调器。另外,请确保将您的微调器声明为MvxSpinner视图。