无法为绑定 SelectedItem 创建目标绑定

Failed to create target binding for binding SelectedItem

我尝试将 MvxListView 的选定项目绑定到我的 属性。这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:fitsSystemWindows="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <include
        layout="@layout/toolbar_actionbar" />
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="6dp"
        android:paddingRight="6dp">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_search_text"
            local:MvxBind="Text SearchText" />
        <MvxListView
            android:id="@+id/category_list"
            android:orientation="vertical"
            android:choiceMode="singleChoice"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            local:MvxItemTemplate="@layout/listitem_category"
            local:MvxBind="ItemsSource Categories; SelectedItem SelectedCategory" />
    </LinearLayout>
</LinearLayout>

这里的ItemSource绑定正确

视图模型:

[ImplementPropertyChanged]
public class SelectCategoryListViewModel : AbstractCategoryListViewModel
{
    /// <summary>
    ///     Creates an CategoryListViewModel for the usage of providing a category selection.
    /// </summary>
    /// <param name="categoryRepository">An instance of <see cref="IRepository{T}" /> of type category.</param>
    /// <param name="dialogService">An instance of <see cref="IDialogService" /></param>
    public SelectCategoryListViewModel(IRepository<Category> categoryRepository,
        IDialogService dialogService) : base(categoryRepository, dialogService)
    {}

    public Category SelectedCategory { get; set; }

    public MvxCommand DoneCommand => new MvxCommand(Done);

    public MvxCommand CancelCommand => new MvxCommand(Cancel);

    private void Done()
    {
        MessageHub.Publish(new CategorySelectedMessage(this, SelectedCategory));
        Close(this);
    }

    private void Cancel()
    {
        Close(this);
    }
}

不是通知 PropertyChanged 是通过 Fody 完成的,类别在父 VM 中。

public class SelectCategoryListActivity : MvxFragmentCompatActivity<SelectCategoryListViewModel>
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.fragment_category_list);

        SetSupportActionBar(FindViewById<Toolbar>(Resource.Id.toolbar));
        SupportActionBar.SetDisplayHomeAsUpEnabled(true);
    }
...

我收到的警告是:

[0:] MvxBind:Warning: 5.11 未能创建用于为 SelectedCategory

绑定 SelectedItem 的目标绑定

想法?

我刚遇到一个类似的问题,SelectedItem 绑定失败。解决方法是将 Mvx 更新到版本 4.1.6。原因是您需要注册 MvxAppCompatSetupHelper.FillTargetFactories,4.1.6 现在可以自动注册了。

或者,您可以通过覆盖 FillTargetFactories:

在 setup.cs 中手动注册它
protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
{
    MvxAppCompatSetupHelper.FillTargetFactories(registry);
    base.FillTargetFactories(registry);
}