CommunityToolkit / CommunityToolkit/Windows

SelectedItem not maintained in ComboBox when property was bound using CommunityToolkit.WinUI.FrameworkElementExtensions

Open
#454 0 comments 0 reactions 0 assignees View on GitHub
bug components::extensions
Dominant language
C#
Stars
1.1k
Forks
166
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

We are using the FrameworkElementExtension.Ancestor for the ComboBox.ItemsSource binding. When we unload the ComboBox, the binding remains active, causing the SelectionChanged event to trigger after the Unloaded event. As a result, the SelectedItem is not maintained in our application. This issue specifically occurs when using the FrameworkElementExtension from the [CommunityToolKit.WinUI.Extensions](https://www.nuget.org/packages/CommunityToolkit.WinUI.Extensions/8.1.240606-rc) package.

Sample - [ComboBox_BindingIssue.zip](https://github.com/user-attachments/files/16064546/ComboBox_BindingIssue.zip)

Unnecessary calls for SelectionChanged event after Unloaded event triggers - [UnnecessaryCallForSelectionChanged.zip](https://github.com/user-attachments/files/16064551/UnnecessaryCallForSelectionChanged.zip)

### Steps to reproduce

```text
Replication Procedure

1.Run the sample
2.Click the drop down of the FrameworkElementExtension Binding combo box.
3.Select Personnel.
4.Click Reset Control button.
```

### Expected behavior

Expected behavior - TextBox Text needs to be remains the same.
Observed behavior - TextBox Text changes to null.

### Screenshots

https://github.com/CommunityToolkit/WindowsCommunityToolkit/assets/124787498/31d24d2f-c438-4715-bac2-db71d9b2697b

### Code Platform

- [ ] UWP
- [X] WinAppSDK / WinUI 3
- [ ] Web Assembly (WASM)
- [ ] Android
- [ ] iOS
- [ ] MacOS
- [ ] Linux / GTK

### Windows Build Number

- [ ] Windows 10 1809 (Build 17763)
- [ ] Windows 10 1903 (Build 18362)
- [ ] Windows 10 1909 (Build 18363)
- [ ] Windows 10 2004 (Build 19041)
- [ ] Windows 10 20H2 (Build 19042)
- [ ] Windows 10 21H1 (Build 19043)
- [ ] Windows 10 21H2 (Build 19044)
- [ ] Windows 10 22H2 (Build 19045)
- [ ] Windows 11 21H2 (Build 22000)
- [ ] Other (specify)

### Other Windows Build number

Windows 11 23H2 (Build 22631.3737)

### App minimum and target SDK version

- [ ] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [ ] Windows 10, version 1909 (Build 18363)
- [X] Windows 10, version 2004 (Build 19041)
- [ ] Windows 10, version 2104 (Build 20348)
- [ ] Windows 11, version 22H2 (Build 22000)
- [ ] Other (specify)

### Other SDK version

_No response_

### Visual Studio Version

2022

### Visual Studio Build Number

17.10.1
### Device form factor

Desktop

### Additional context

I used these Nuget Packages.
CommunityToolKit.WinUI.Extensions - version - 8.0.240109
CommunityToolKit.Mvvm - version - 8.2.2
Microsoft.Windows.SDK.BuildTools - version - 10.0.22621.765
MicrosoftWindowsSDKApp - version - 1.5.240607001

I have also created the same query in the WindowsCommunityToolKit repo too. But I didn't get any updates. So, I created here.
Query Link - https://github.com/CommunityToolkit/Windows/issues/546

### 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.