【发布时间】:2019-03-09 15:06:39
【问题描述】:
在将 MvxListView 绑定到我的 ViewModel 时,我似乎遇到了一个奇怪的问题。我已经对 ViewModel 进行了三次检查,并且可以确认它连接正确,因为其他两种原始类型绑定正确。
但是,当我尝试绑定到 ObservableCollection(或 MvxObservableCollection)时,在 MvxListView 中没有呈现任何项目。我跟踪了调试日志,看不到任何 MvvmCross 错误,也看不到任何 Android 膨胀问题。
我已经尝试了各种提高 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" />
【问题讨论】:
标签: android xamarin mvvmcross mvxlistview