Forum Xamarin Xamarin.Forms

ViewCell ContextAction Selection changed

HannesHasenauerHannesHasenauer ATMember
edited June 2016 in Xamarin.Forms

Hello everyone,
I ran into a problem which I'm not able to solve on my own.
I'm working on an messaging app for a transport logistic purpose.
My idea was to use the context action of the List View for all operations of the order.

  • Cancel
  • Finish
  • Defer
  • Advance the order state

The problem I ran into was with advancing the order state, as I want to bind the name of the next order state as the button text.
With iOS everything is working fine, as the context menu only allows one selection at the time.
The problem is with android as you can still switch items after opening the context menu.
And doing so does not update the description of the button.
I see two approaches to negate this problem.

  • One being to update the binding somehow (the problem here is, that I do not get any event [tapped or selected] when the context menu is already open
  • The other one (the one I would prefer) would be to not allow changing the selected item the context action is called from after the context menu is open (This would prevent user input errors)

Unfortunately I have no idea how to achieve that, as I do not find any event or command I could use to intercept.

The context action looks like this
<ViewCell.ContextActions> <MenuItem Text="{Binding OrderState}" Command="{Binding NextOrderState}" CommandParameter="{Binding .}" /> <MenuItem Text="{i18n:Translate FinishOrderButton}" Command="{Binding FinishOrder}" CommandParameter="{Binding .}" /> <MenuItem Text="{i18n:Translate CancelOrderButton}" Command="{Binding CancelOrder}" IsDestructive="True" CommandParameter="{Binding .}" /> <MenuItem Text="{i18n:Translate DeferOrderButton}" Command="{Binding DeferOrder}" CommandParameter="{Binding .}" /> </ViewCell.ContextActions>

Thanks in advance for any idea how to solve this!

PS: The more MVVM conform the approach is, the better ;)

Cheers Hannes


  • ThomasBurkhartThomasBurkhart DEMember ✭✭✭✭

    What about setting isEnabled=false of the ListView when an Action is Selected

  • HannesHasenauerHannesHasenauer ATMember
    edited June 2016

    The problem is I would need to disable the ListView before an action is selected. Because I do not want the user to change the selection in the timespan between opening the context menu and selecting the action within the context menu.
    And after the context menu is opened I do not seem to get any selection and / or tapped events anymore.
    Thanks for your input though!

  • ThomasBurkhartThomasBurkhart DEMember ✭✭✭✭
    edited June 2016

    You should have a Look at MrGesture
    @MichaelRumpler Is it possible to pass an Touchevent that MrGesture caputeres on to the Underlying Control after Taking some Action?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Very strange. I think it's not a correct situation

  • HannesHasenauerHannesHasenauer ATMember

    What is even more strange than the fact none of the selection events gets fired when changing the selection when the context menu is open is, that neither the BindingContextChanged event of the ViewCell.ContextActions nor the BindingContextChanged of the MenuItem within get fired. I'm really confused how it is possible that the CommandParameter is changing in this scenario...
    If the CommandParameter would not change neither I would not event run into this problem...

Sign In or Register to comment.