我正在使用this库将BottomNavigationBar
添加到我的项目中。我也在这个项目的框架中使用MvvmCross。不过,我不知道如何将MvxCommand
绑定到我的BottomBar
。有谁知道这是怎么做到的吗?
下面是我在ViewModel
中使用的MvxCommand
的大致外观:
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
}
发布于 2017-07-12 15:23:40
如果您像这样声明您的活动:
public class MyView : MvxActivity<MyViewModel>
您将能够访问类型为"MyViewModel“的属性"ViewModel”。
然后,您只需使用以下命令调用您的命令:
ViewModel.OnTabSelectedCommand.Execute();
此调用应与切换命令一起包含在您的:
public void OnMenuTabSelected(int menuItemId)
{
// Do something
}
https://stackoverflow.com/questions/45019667
复制相似问题