我关注this tutorial以及他们使用mvxbind将他们的Home,Info和第三个片段用于他们各自的视图模型的方式。我尝试对我的其他片段做同样的事情,但我不知道我做错了什么,但是MvxBind没有用。这是我的viewmodel和layout的代码。
SomeViewModel.cs
public class SomeViewModel : BaseViewModel
{
public SomeViewModel()
{
}
private MvxCommand someViewModelCommand;
public MvxCommand SomeViewModelCommand
{
get
{
someViewModelCommand = someViewModelCommand ?? new MvxCommand(DoSomeViewModel);
return someViewModelCommand;
}
}
private void DosomeViewModel()
{
ShowViewModel<FirstViewModel>();
}
}
FirstViewModel.cs
public class FirstViewModel : BaseViewModel
{
public FirstViewModel()
{
First = "Some Info for you...";
}
public string First
{
get;
private set;
}
}
现在我有这样的布局: SomeLayout
<?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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<Button
android:id="@+id/someButton"
android:text="Do Something"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="Click SomeViewModelCommand" />
</LinearLayout>
更新
SomeFragment.cs
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
// return inflater.Inflate(Resource.Layout.YourFragment, container, false);
ShowHamburgerMenu = true;
oldTitle = ((MainActivity)Activity).Title;
((MainActivity)Activity).Title = "Track Packages";
//var view = base.OnCreateView(inflater, container, savedInstanceState);
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.fragment_trackpackage, container, false);
return view;
}