dotnet / dotnet/maui

CollectionView's SelectionChanged method cannot be triggered when tapping the item directly

Open
#9,567 22 comments 10 reactions 0 assignees View on GitHub
area-controls-collectionview has-workaround p/2 partner/syncfusion platform/android s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

CollectionView's SelectionChanged method cannot triggered when tapping the item directly.

### Steps to Reproduce

1.create a maui app;

2.copy the following code to the MainPage.xaml:

```
















```

MyViewModel.cs

```
public class MyViewModel: INotifyPropertyChanged
{
public ObservableCollection Data { get; set; }

public ICommand RemoveEquipmentCommand => new Command(ReMoveItem);

private void ReMoveItem(MyModel obj)
{
System.Diagnostics.Debug.WriteLine(" the selected item's name is: " + obj.Name );

Data.Remove(obj);
}

public MyViewModel() {
Data = new ObservableCollection();

Data.Add(new MyModel { Name ="model_1", Car= new Vehicle {Make="Make1" } });
Data.Add(new MyModel { Name = "model_2", Car = new Vehicle { Make = "Make2" } });
Data.Add(new MyModel { Name = "model_3", Car = new Vehicle { Make = "Make3" } });
Data.Add(new MyModel { Name = "model_4", Car = new Vehicle { Make = "Make4" } });

}

bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Object.Equals(storage, value))
return false;

storage = value;
OnPropertyChanged(propertyName);
return true;
}

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

public event PropertyChangedEventHandler PropertyChanged;
}
```

3.Deploy the app to a android device, and tap directly on the item, the SelectionChanged method is not being triggered and will be triggered only if clicking on the frame border or outside of it.

### Version with bug

Unknown/Other (please specify)

### Last version that worked well

Unknown/Other

### Affected platforms

Android

### Affected platform versions

android 10

### Did you find any workaround?

_No response_

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue on an Android 10 device using the CollectionView in MainPage.xaml and the model in MyViewModel.cs. Compare tapping the item content with tapping its border, then trace the SelectionChanged behavior. Done means SelectionChanged is triggered when the item is tapped directly, while the delete command still removes the intended item.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.