There is a ListView cell class. Inside at initialization we add

MenuItem myMenuItem _deleteSwipeButton = new MenuItem { IsDestructive = true, }; ContextActions.Add(myMenuItem);

Next on the page where the ListView is located, some actions take place. And at some point for certain cells, you need to hide the MenuItem . Those. there is a condition some bool 'evske by which you can define to hide (or delete, in this case without a difference) the MenuItem or leave it at the cell. Standard Binding 'and I did not find.

MenuItem does not have an IsVisibleProperty property.

Perhaps someone has already encountered this and can suggest how you can hide the MenuItem element by condition? Thanks for the help.

  • Catch the opening of the context menu and choose what to show and what not. - Monk
  • @Monk and through binding it is impossible to tie in any way? - DarkOwl
  • Sure you may. Just once you add elements during initialization, I suggested a similar method - on the request for display. You can create a view_model for the context menu item, bind its visibility and steer it. PS: I’m talking mostly about WPF, the rest needs to be checked, but I have nothing. - Monk
  • @Monk It's just that some other logic is required. Elements are set start-up during initialization and their further behavior is controlled through bindings. And the actions of the user through them already affect the components that were immediately placed on the page. - DarkOwl

1 answer 1

I came across the following question and answer: https://forums.xamarin.com/discussion/20676/is-it-possible-to-hide-a-toolbaritem

How it worked for me: Add a new property to bind:

private static readonly BindableProperty MyVisibleProperty = BindableProperty.Create<MyListCell, bool> (ctrl => ctrl.myGetterBool, defaultValue: false, defaultBindingMode: BindingMode.OneWay, propertyChanging: (bindable, oldValue, newValue) => { if (oldValue != newValue) { var page = (MyListCell)bindable; if (newValue == true && page.ContextActions.Contains(page.myMenuItem)) { page.ContextActions.Remove(page.myMenuItem); } else if (newValue == false && !page.ContextActions.Contains(page.myMenuItem)) { page.ContextActions.Add(page.myMenuItem); } } });

Binding:

this.SetBinding<MyViewModel>(MyListCell.MyVisibleProperty, v => v.MyBool);

MyBool - the result of my checks (bool)