CommunityToolkit / CommunityToolkit/dotnet

SelectionChangedCommandParameter is evaluated before SelectedItem updates in .NET 11

Open
#1,165 4 comments 0 reactions 0 assignees View on GitHub
bug :bug: mvvm-toolkit :toolbox: needs author feedback :memo:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

When using CommunityToolkit-generated commands with CollectionView, the SelectionChangedCommandParameter is evaluated before the SelectedItem binding is updated in .NET 11.
This behavior differs from .NET 10, where the bound SelectedItem was already updated when the command executed.
As a result, commands that rely on ViewModel properties (for example, SelectedItem) receive null or stale values.

- The command executes before the SelectedItem binding is updated.
- SelectionChangedCommandParameter is null or contains the previous value.
- This breaks scenarios that rely on ViewModel-bound properties inside the command.

### Regression

8.0.3

### Steps to reproduce

Run the attached sample.
Tap/select an item in the CollectionView.
Observe that SelectionChangedCommand is invoked.
Inspect the value of SelectionChangedCommandParameter.

### Expected behavior

SelectionChangedCommandParameter should receive the updated selected item (or the updated ViewModel property) when the command executes.

### Screenshots

_No response_

### IDE and version

VS 2022

### IDE version

_No response_

### Nuget packages

- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [ ] CommunityToolkit.Mvvm (aka MVVM Toolkit)

### Nuget package version(s)

8.0.4

### Additional context

_No response_

### Help us help you

Yes, I'd like to be assigned to work on this item

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.