Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to close context action via code in xamarin forms

SupreetTare.9314SupreetTare.9314 GBUniversity ✭✭
edited December 2015 in Xamarin.Forms

I have created an app in xamarin forms, where I have used Context Actions in a list view item template's ViewCell as:

     <MenuItem Clicked="OnActiveJourneyEdit" 
     <MenuItem Clicked="OnActiveJourneyDelete" 
                         IsDestructive="True" />

While I long press on any item in the list view I get context action items in action bar, and if I do not tap on any option in context action it will not be closed in android. Is there any way so that I can close that context action bar via code in xamarin forms?

Getting issue with context action on android, context menu is remained open while tapping on other buttons on the page, can anyone help to close the context action menus in xamarin forms.

Also please check the link for the same :


  • AndrewStephens.1111AndrewStephens.1111 USUniversity ✭✭

    Any update on this?

  • On Android, ContentAction are implemented with ActionModes and I don't see a way to close an action mode without having a reference to it. And, I don't see a way to get the action mode from our code since all of that is hidden inside the Android renderers. I also tried just programmatically clicking the back button since that closes the action mode but that did too much. It closed the aciton mode and also went back a page.

    So I don't think this is possible today.

  • MatheusSilvaMatheusSilva USMember ✭✭

    Hi @SupreetTare.9314, I have the same question, did you find the solution?

  • voidvoid DKBeta ✭✭✭
    edited November 2016

    I have this requirement as well. Especially on Android.

    Forms Team: Either you go modal and disallow any other UI events while in a context action state, or you give us a listview method to cancel the whole damn thing.

    iOS just works. As usual.

  • AdrianKnightAdrianKnight USMember ✭✭✭✭

    I can work on this tonight. I pushed a PR last night to fix another issue. I like the idea of having a ListView method to close context actions programmatically.

  • DavidDancyDavidDancy AUMember ✭✭✭✭

    @AdrianKnight You're amazing - and your recent truckload of work on the XF system has been much appreciated.

  • AdrianKnightAdrianKnight USMember ✭✭✭✭

    @DavidDancy Thanks. :) Last night, I was able to handle the cases for iOS and Android, but for some reason UWP context actions didn't seem to be working (i.e. long pressing cells doesn't open up the context menu). I'm not sure if this is an existing issue.

  • leeaptedleeapted Member ✭✭

    @AlejandroRuiz Thanks. Your example really helped me.

    I had an issue involving a gesturerecognizer (tapped event) and a contextaction in a viewcell for a listview. Both were getting called on a long press. I adapted your code to create a dependency service that returns the status of actionmode and I check it in the tapped event handler.

Sign In or Register to comment.