【问题标题】:MvvmCross Fragment binding doesn't workMvvmCross 片段绑定不起作用
【发布时间】:2015-11-23 00:36:30
【问题描述】:

我有这个布局:

<cirrious.mvvmcross.binding.droid.views.MvxListView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:local="http://schemas.android.com/apk/res-auto"
  android:id="@+id/accountList"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  local:MvxItemTemplate="@layout/accountlistitem"
  local:MvxBind="ItemsSource AllAccounts" />

使用以下代码将布局加载到片段中:

public new AccountListViewModel ViewModel
{
    get { return (AccountListViewModel)base.ViewModel; }
    set { base.ViewModel = value; }
}

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    var ignore = base.OnCreateView(inflater, container, savedInstanceState);
    return this.BindingInflate(Resource.Layout.AccountListLayout, null);
}

在我的 ViewModel 中(Property Changed 是通过 fody 注入的):

public ObservableCollection<Account> AllAccounts
{
    get { return accountRepository.Data; }
    set { accountRepository.Data = value; }
}

这不起作用,也不会显示任何数据。但是当我将以下行添加到片段时,我的数据会正确显示:

    var list = view.FindViewById<MvxListView>(Resource.Id.accountList);
    list.ItemsSource = ViewModel.AllAccounts;

在另一个示例中,这在稳定版本上没有任何问题。此外,绑定似乎在活动中起作用,但在片段中不起作用。对于这个项目,我使用 v4.0.0 beta2。我错过了什么吗?

GitHub 存储库链接:https://github.com/NPadrutt/MoneyManager

谢谢

【问题讨论】:

  • 我遇到了同样的问题。我的项目使用 AppCompat 功能。我必须先添加 Cirrious.MvvmCross.Droid.Support.AppCompat,然后绑定才能在 v4 beta 2 中工作。不确定这是否适合你,只是提到它对我有用。
  • 不幸的是,这并没有改变任何东西。有趣的是,它只出现在片段中。正常活动的绑定工作正常。

标签: android xamarin mvvmcross


【解决方案1】:

我从当前的开发分支构建了自己的 dll。到这里问题就解决了。所以看来解决方案就是等待 beta3 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 2020-12-21
    相关资源
    最近更新 更多