我正在使用ViewPager實現MvvmCross 4.0.0-beta5中的選項卡。但是,ViewModel的EditText綁定屬性始終爲空。我也嘗試更新到MvvmCross 4.0.0-beta7,但沒有運氣。與ViewModel ViewPager綁定問題
這裏是我的ViewPager
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/mspManagerToolbar"
layout="@layout/mspmanagertoolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
local:tabGravity="fill"
local:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
local:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.AppBarLayout>
這裏是我的標籤視圖
<EditText
...
local:MvxBind="Text Title" />
以上的EditText約束力不工作。標題始終爲空。
<EditText
...
local:MvxBind="Text User.Title" />
上面的EditText綁定工作完美。 User.Title獲得正確的價值。
這裏ViewPagerView.cs代碼
public class CustomerDetailView : MvxCachingFragmentCompatActivity<CustomerDetailViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.CustomerDetailView);
// Use toolbar as action bar
var toolbar = FindViewById<Toolbar>(Resource.Id.mspManagerToolbar);
if (toolbar != null)
{
// Toolbar will now take on default actionbar characteristics
SetSupportActionBar(toolbar);
}
// View Pager
var viewPager = FindViewById<ViewPager>(Resource.Id.viewpager);
if (viewPager != null)
{
// Add tabs in view pager
var fragments = new List<MvxFragmentStatePagerAdapter.FragmentInfo>
{
new MvxFragmentStatePagerAdapter.FragmentInfo(TAB_DETAIL, typeof(Tab_CustomerDetail), typeof(CustomerDetailViewModel)),
new MvxFragmentStatePagerAdapter.FragmentInfo(TAB_CONTACT, typeof(Tab_CustomerContact), typeof(CustomerDetailViewModel)),
new MvxFragmentStatePagerAdapter.FragmentInfo(TAB_LOCATION, typeof(Tab_CustomerLocation), typeof(CustomerDetailViewModel)),
new MvxFragmentStatePagerAdapter.FragmentInfo(TAB_CONTRACT, typeof(Tab_CustomerContract), typeof(CustomerDetailViewModel))
};
viewPager.Adapter = new MvxFragmentStatePagerAdapter(this, SupportFragmentManager, fragments);
}
var tabLayout = FindViewById<TabLayout>(Resource.Id.tabs);
tabLayout.SetupWithViewPager(viewPager);
}
}
這是我的代碼片段
[Register("app.droid.views.fragments.Tab_CustomerDetail")]
public class Tab_CustomerDetail : MvxFragment
{
#region Public Method
/// <summary>
/// tab customer detail view
/// </summary>
/// <param name="inflater"></param>
/// <param name="container"></param>
/// <param name="savedInstanceState"></param>
/// <returns></returns>
public override View OnCreateView(Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState)
{
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.frg_tab_CustomerDetail, null);
return view;
}
#endregion
}
這裏是視圖模型屬性
public string Title
{
get
{
return (title);
}
set
{
if (value != title)
{
title = value;
RaisePropertyChanged(() => this.Title);
}
}
}
public User User
{
get
{
return (repositoryService.User);
}
set
{
repositoryService.User = value;
RaisePropertyChanged(() => User);
}
}
Title屬性越來越空,User.Title正在完善。那麼請讓我知道我哪裏錯了?
您的適配器設置是什麼樣的? –
@DerekBeattie:我更新了我的帖子,現在添加了查看分頁器佈局和MvxFragmentStatePagerAdapter。請看一次,並幫助解決。 –
片段代碼是什麼樣的? –