MvvmCross MvxListView 项目未在 Android 上呈现

MvvmCross MvxListView Items Not Rendering on Android

在将 MvxListView 绑定到我的 ViewModel 时,我似乎遇到了一个奇怪的问题。我已经对 ViewModel 进行了三重检查,可以确认它已正确连接,因为其他两个基本类型已正确绑定。

但是,当我尝试绑定到 ObservableCollection(或 MvxObservableCollection)时,我没有在 MvxListView 中呈现任何项目。我跟踪了调试日志,看不到任何 MvvmCross 错误,也看不到任何 Android inflation 问题。

我已经尝试了多种方法来提高 propertychanged,正如您将在我的代码中看到的那样。

这让我发疯!任何帮助将不胜感激。也许我错过了一些愚蠢的东西。

视图模型:

private MvxObservableCollection<ReminderDto> _reminders;

    public MainViewModel(IApiService apiService)
    {
        _apiService = apiService;
    }

    public override void ViewAppearing()
    {
        Reminders = new MvxObservableCollection<ReminderDto>()
        {
            new ReminderDto() { Description = "Test" },
            new ReminderDto() { Description = "Test" },
            new ReminderDto() { Description = "Test" },
            new ReminderDto() { Description = "Test" },
            new ReminderDto() { Description = "Test" },
            new ReminderDto() { Description = "Test" },
            new ReminderDto() { Description = "Test" },
        };

        RaisePropertyChanged(nameof(Reminders));
    }

    public MvxObservableCollection<ReminderDto> Reminders
    {
        get { return _reminders; }
        set { SetProperty(ref _reminders, value); }
    }

MainView.axml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<MvxListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            local:MvxBind="ItemSource Reminders"
            local:MvxItemTemplate="@layout/reminder_row" />

项目模板(reminder_row.axml)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/reminder_danger"
android:weightSum="6">
<TextView
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="25px"
    android:minHeight="25px"
    android:id="@+id/textView1" />

加载集合的 属性 是 ItemsSource,而不是 ItemSource。 替换为:

local:MvxBind="ItemSource Reminders"

有了这个:

local:MvxBind="ItemsSource Reminders"