Xamarin MvvmCross在ViewModel中初始化弹出菜单

时间:2017-09-25 14:19:47

标签: c# xamarin xamarin.android mvvmcross

是否可以在ViewModel中初始化弹出菜单?

enter image description here

现在我正在View上初始化它:

var button = activity.FindViewById(Resource.Id.moreButton);

button.Click += (s, arg) =>
{
    PopupMenu menu = new PopupMenu(activity, button);
    menu.Inflate(Resource.Menu.PopupMenu);
    menu.Show();

    menu.MenuItemClick += (s1, arg1) =>
    {
        switch (arg1.Item.TitleFormatted.ToString())
        {
            case "Profile":
                activity.StartActivity(typeof(ProfileView));
                break;
            case "Prices":
                break;
            case "Terms":
                activity.StartActivity(typeof(TermsView));
                break;
            case "Privacy":
                activity.StartActivity(typeof(PrivacyView));
                break;
        }
    };
};

但是在我的.axml文件中,我想用MvxBind绑定“打开弹出菜单”按钮,这样就可以了。我怎么能这样做?

更新1

或者也许可以像这样绑定xml文件上的点击,因为现在它显然不起作用......

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:local="http://schemas.android.com/apk/res-auto">
 <item android:id="@+id/profile"
    android:title="Profile"
    local:MvxBind="Click GoProfileCommand"/>
  <item android:id="@+id/prices"
    android:title="Prices"/>
  <item android:id="@+id/terms"
    android:title="Terms"
    local:MvxBind="Click GoTermsCommand"/>
  <item android:id="@+id/privacy"
    android:title="Privacy"
    local:MvxBind="Click GoPrivacyCommand"/>

0 个答案:

没有答案