Forum Xamarin.Forms

Is there an event I can handle just prior to Context Actions being displayed?

I currently have a ListView, for which each item in the ListView has a set of Context Actions. Which Context Actions are enabled or disabled at any point (which will hopefully be changed to which are present or not present shortly) changes depending on some state from outside the ListView. At the moment, I am using a Command handler and CanExecute to have each of the Context Actions update when the external state changes. This is horribly inefficient and I am currently investigating a memory leak relating to this on iOS.

My thinking is that it would be better if rather than having Context Actions updating on all of the list items, it would make far more sense to identify which item is being asked to display Context Actions and only then add the Context Actions to that item, removing them again when the Context Actions are no longer displayed. To do this I would need to react to an event saying that the Context Actions are about to be displayed, and another event saying that they are no longer being displayed. It wouldn't be ItemSelected or ItemTapped, nor ItemAppearing/ItemDisappearing. Does anybody know how I can be notified when Context Actions want to be displayed (even though they haven't been added yet), and again when they are being removed from the display?

Many thanks,

John H.


  • JohnHardmanJohnHardman GBUniversity mod

    If there's no suitable event, I'm thinking I'll have to create my own context menu rather than using Context Actions. That'll be a shame - I'd rather use the built-in stuff, but am slowly bypassing more and more of it :-(

  • AdamPAdamP AUUniversity ✭✭✭✭✭
    edited February 2016

    @JohnHardman - I always find your questions an interesting challenge :)

    (going through dotPeek again). There are no events for it. However there is a public HasContextActions property on the cell but it is readonly and unfortunately bases it on contextActions.Count

    It returns the IsEnabled property, so if you set the cell to IsEnabled = false then the ContextAction shouldn't occur, rather than trying to intercept an event.

  • JohnHardmanJohnHardman GBUniversity mod

    @AdamP - Many thanks for looking at this. I try to make the questions challenging ;-) (Just kidding!).

    I really should take a look at dotPeek one of these days. I've been putting it off as poking around at that sort of level is the sort of thing that distracts me from what I should be doing (too many years of working in assembly languages!).

    After spending a while on this today, I've come to the conclusion that I am going to re-work the screen where this was an issue and create my own context menu in order to make things faster, use less memory, and look more consistent. That'll be a job for tomorrow.

    Thanks again.

Sign In or Register to comment.