如何将 MvxCommand 附加到 BottomBar?
How can I attach a MvxCommand to a BottomBar?
我正在使用 this 库将 BottomNavigationBar
添加到我的项目中。我还在这个项目的框架中使用 MvvmCross。不过,我不知道如何将 MvxCommand
绑定到我的 BottomBar
。有谁知道如何做到这一点?
我的 MvxCommand
在 ViewModel
中大致是这样的:
public ICommand OnTabSelectedCommand
{
get { return New MvxCommand(() => OnTabSelected()); }
}
我的 BottomBar
作品是这样的:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var recycler = FindViewById<MvxRecyclerView>(Resource.Id.menuList);
var layoutManager = new LinearLayoutManager(this);
recycler.SetLayoutManager(layoutManager);
recycler.NestedScrollingEnabled = false;
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbarFinder);
SetSupportActionBar(toolbar);
_bottomBar = BottomBar.AttachShy((CoordinatorLayout)FindViewById(Resource.Id.ListCoordinator),
FindViewById(Resource.Id.menuList), savedInstanceState);
_bottomBar.SetItems(new[]
{ new BottomBarTab(Resource.Drawable.ic_recents, "Recents"),
new BottomBarTab(Resource.Drawable.ic_favorites, "Favorites"),
new BottomBarTab(Resource.Drawable.ic_nearby, "Nearby") }
);
_bottomBar.SetOnMenuTabClickListener(this);
_bottomBar.SetActiveTabColor(Color.Red);
_bottomBar.MapColorForTab(0, "#7B1FA2");
_bottomBar.MapColorForTab(1, "#FF5252");
_bottomBar.MapColorForTab(2, "#FF9800");
}
public void OnMenuTabSelected(int menuItemId)
{
// Do something
}
public void OnMenuTabReSelected(int menuItemId)
{
// Do Something
}
如果您这样声明 Activity:
public class MyView : MvxActivity<MyViewModel>
您将能够访问类型为 "MyViewModel".
的 属性 "ViewModel"
然后你只需要调用你的命令:
ViewModel.OnTabSelectedCommand.Execute();
此调用应包含在您的切换命令中:
public void OnMenuTabSelected(int menuItemId)
{
// Do something
}
我正在使用 this 库将 BottomNavigationBar
添加到我的项目中。我还在这个项目的框架中使用 MvvmCross。不过,我不知道如何将 MvxCommand
绑定到我的 BottomBar
。有谁知道如何做到这一点?
我的 MvxCommand
在 ViewModel
中大致是这样的:
public ICommand OnTabSelectedCommand
{
get { return New MvxCommand(() => OnTabSelected()); }
}
我的 BottomBar
作品是这样的:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var recycler = FindViewById<MvxRecyclerView>(Resource.Id.menuList);
var layoutManager = new LinearLayoutManager(this);
recycler.SetLayoutManager(layoutManager);
recycler.NestedScrollingEnabled = false;
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbarFinder);
SetSupportActionBar(toolbar);
_bottomBar = BottomBar.AttachShy((CoordinatorLayout)FindViewById(Resource.Id.ListCoordinator),
FindViewById(Resource.Id.menuList), savedInstanceState);
_bottomBar.SetItems(new[]
{ new BottomBarTab(Resource.Drawable.ic_recents, "Recents"),
new BottomBarTab(Resource.Drawable.ic_favorites, "Favorites"),
new BottomBarTab(Resource.Drawable.ic_nearby, "Nearby") }
);
_bottomBar.SetOnMenuTabClickListener(this);
_bottomBar.SetActiveTabColor(Color.Red);
_bottomBar.MapColorForTab(0, "#7B1FA2");
_bottomBar.MapColorForTab(1, "#FF5252");
_bottomBar.MapColorForTab(2, "#FF9800");
}
public void OnMenuTabSelected(int menuItemId)
{
// Do something
}
public void OnMenuTabReSelected(int menuItemId)
{
// Do Something
}
如果您这样声明 Activity:
public class MyView : MvxActivity<MyViewModel>
您将能够访问类型为 "MyViewModel".
的 属性 "ViewModel"然后你只需要调用你的命令:
ViewModel.OnTabSelectedCommand.Execute();
此调用应包含在您的切换命令中:
public void OnMenuTabSelected(int menuItemId)
{
// Do something
}