How to use actionbar with Xamarin and MvvmCross

前端 未结 1 1375
北海茫月
北海茫月 2021-02-10 06:41

I\'ve seen Xamarin recently released as component http://components.xamarin.com/view/xamandroidsupportv7appcompat

I would like to use it with MvvmCross in my app, but I

相关标签:
1条回答
  • 2021-02-10 06:43

    There is no way to bind ActionBar to ICommands with MvvmCross. But you can use a simple trick and call into your ICommands from the activity when a button on ActionBar is pressed.

    public override bool OnCreateOptionsMenu(IMenu menu)
    {
        this.MenuInflater.Inflate(Resource.Menu.QuoteDetails, menu);
    
        m_MenuItem_EditQuote = menu.FindItem(Resource.Id.menu_EditQuote);
        m_MenuItem_EditQuote.SetVisible(ViewModel.CanEdit);
    
        return true;
    }
    
    public override bool OnOptionsItemSelected(IMenuItem item)
    {
        switch (item.ItemId)
        {
    
            case Resource.Id.menu_EditQuote:
    
                ViewModel.EditQuoteCommand.Execute(null);
                return true;
    
            case Resource.Id.menu_ViewQuote:
    
                ViewModel.DownloadQuoteCommand.Execute(null);
                return true;
    
            case Resource.Id.menu_EmailQuote:
    
                ViewModel.EmailQuoteCommand.Execute(null);
                return true;
    
            default:
                return base.OnOptionsItemSelected(item);
        }
    }
    
    0 讨论(0)
提交回复
热议问题