Bug 52382 - iOS ListView ContextAction not retracted when clicked if bound Command is changed dynamically
Summary: iOS ListView ContextAction not retracted when clicked if bound Command is cha...
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.4
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-02-08 14:29 UTC by Christiaan de Jong
Modified: 2017-11-28 17:30 UTC (History)
3 users (show)

Tags: ios, contextactions, listview, ac
Is this bug a regression?: ---
Last known good build:

Visual Studio Solution (packages directory was too big) (251.36 KB, application/x-zip-compressed)
2017-02-08 14:29 UTC, Christiaan de Jong
Example of the broken behavior (5.06 MB, image/gif)
2017-11-28 17:30 UTC, Rob Gibbens

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 52382 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Christiaan de Jong 2017-02-08 14:29:35 UTC
Created attachment 19759 [details]
Visual Studio Solution (packages directory was too big)

Items in a ListView can have ContextActions. On iOS, I can show these by swiping a list item to the left. The ContextActions will become visible. If I click on a ContextAction, a (bound) Command can be executed, and the list item gets automatically swiped back. However, this does not seem to be the case if the bound Command gets changed dynamically.

I created a very small example with a ListView with an item. The item has a few bindings, one of which is the text and Command of a ContextAction MenuItem. Below the ItemTemplate for the ListView items.

                    <MenuItem Command="{Binding CurrentCommand}" Text="{Binding Cycle}" />
                    <MenuItem Command="{Binding ShowAlert}" Text="ShowAlert" />
                <Label Text="{Binding Cycle}" TextColor="Navy" />

I put in a ListEntryViewModel:

    public class ListEntryViewModel : INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        private readonly Command[] _commands;
        private string _cycle;
        private Command _currentCommand;

        public string Cycle
            get { return _cycle; }
                _cycle = value;

        public Command ShowAlert { get; set; }

        public Command CurrentCommand
            get { return _currentCommand; }
                _currentCommand = value;

        void OnPropertyChanged([CallerMemberName] string propertyName = null)
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

        public ListEntryViewModel()
            ShowAlert = new Command(() => Application.Current.MainPage.DisplayAlert("Alert", "It should slide back", "OK"));
            _commands = new Command[]
                new Command(() => show("First", 1, "string is 'First'")),
                new Command(() => show("Second", 2, "string is now 'Second'")),
                new Command(() => show("Third", 0, "string is now 'Third'"))

        private void show(string cycle, int newIndex, string message)
            Cycle = cycle;
            CurrentCommand = _commands[newIndex];

See attachment for full code. Each time I click the ShowAlert ContextAction, the item in the ListView is retracted/swiped back, which is default iOS behaviour, but if I click the other (dynamic) ContextAction, The command gets executed, the Text of both the Item and the ContextAction get visibly changed, but the row/ListView item is NOT retracted.

On Android and UWP the ContextActions do work as expected.
Comment 1 Jimmy [MSFT] 2017-03-16 21:08:47 UTC
I was able to reproduce this issue with the attached repro project on iOS. As mentioned in the description, this does _not_ occur on Android or UWP. I am confirming this report so the team can investigate further.

### Steps to Reproduce
1. Run the attached iOS project
2. Swipe left on the "First" cell to reveal the context actions
3. Click the "First" action item

### Expected Results
The cell should close the context actions. To see the expected result press the "Show Alert" item.

### Actual Results
The cell does not close the context actions

### Version Tests    BAD
2.3.4-pre5          BAD
2.3.4-pre2          BAD
Comment 2 Rob Gibbens 2017-11-28 17:30:06 UTC
Created attachment 25852 [details]
Example of the broken behavior

I'm also seeing this behavior, and have added a gif of what it looks like in action.