我正在使用 this库添加 BottomNavigationBar
到我的项目。我也在为我的这个项目的框架使用 MvvmCross。我不知道如何绑定(bind) 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
}
最佳答案
如果您像这样声明您的事件:
public class MyView : MvxActivity<MyViewModel>
您将能够访问“MyViewModel”类型的属性“ViewModel”。
然后你只需要调用你的命令:
ViewModel.OnTabSelectedCommand.Execute();
此调用应包含在您的 switch 命令中:
public void OnMenuTabSelected(int menuItemId)
{
// Do something
}
关于c# - 如何将 MvxCommand 附加到 BottomBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45019667/