0
我在我的Android應用程序上使用MvvmCross。我有1個與2周的ViewModels(從MvxViewModel
都獲得)的全球視圖模型:將ViewModel綁定到View DataContext
public class GlobalViewModel : MvxViewModel
{
private SubViewModel1 _subViewModel1;
public SubViewModel1 SubViewModel1
{
get { return _subViewModel1; }
set { _subViewModel = value; RaisePropertyChanged(() => SubViewModel); }
}
private SubViewModel2 _subViewModel2;
public SubViewModel2 SubViewModel
{
get { return _subViewModel2; }
set { _subViewModel2 = value; RaisePropertyChanged(() => SubViewModel); }
}
}
在我的XML,我想在第2周個子的ViewModels綁定到的從MvxLinearLayout
得到我的自定義視圖中的數據方面:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
<MyMvxLinearLayout1
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
local:MvxBind="SubViewModel1" />
<MyMvxLinearLayout2
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:gravity="center"
local:MvxBind="SubViewModel2" />
</FrameLayout>
但MyMvxLinearLayout1
和MyMvxLinearLayout2
內部的綁定不起作用。有什麼我失蹤?
請問您的自定義'MvxLinearLayout'公開一個屬性,你想要綁定你的子視圖模型?您將需要一個屬性來控制ViewModel。 – Plac3Hold3r
這實際上不是我想要做的。我試圖綁定到視圖的數據上下文。在WPF和Window Phone中,這是通過綁定到'DataContext'屬性來完成的。 – Darius