我正在使用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
}
答案 0 :(得分:2)
如果您将此活动声明为:
ViewModel.OnTabSelectedCommand.Execute();
您将可以访问该物业&#34; ViewModel&#34;属于&#34; MyViewModel&#34;。
然后你只需要用以下命令调用你的命令:
public void OnMenuTabSelected(int menuItemId)
{
// Do something
}
此调用应包含在您的开关命令中:
VALUE