Open Mangepange opened 1 week ago
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Describe the bug
I noticed that when I used Behaviors on content in TabViewItems, and on their headers, they behave irratically when removing tabs, and adding them back again.
It seems that the TabView recognizes the viewmodel that I add back again, and reuses an old TabViewItem where the Behaviors has been detached. The behavior is re-attached for the TabViewItems content, but the behavior in its header is never reattached.
Also, it seems that when removing the currently selected tab, the next selected TabViewItem does not attach its behaviors correctly.
I can probably manage to get around parts of the issue if I skip detaching my behaviors, but I'm a bit surprised that the TabView reuses old TabViewItems.
Steps to reproduce the bug
I wrote a small example that illustrates the issue. A behavior sets the text foreground color to green or red, depending on if it is attached or detached.
Initial state![image](https://github.com/microsoft/microsoft-ui-xaml/assets/10757343/7946e5f0-fd05-4f12-87c0-be87248a5627)
Removed the viewmodel B, and added it back again. Now the behavior for the 'C' content is detached, and also for the 'B' header.![image](https://github.com/microsoft/microsoft-ui-xaml/assets/10757343/92bb8495-5718-4e2f-930a-5f14c51d0de9)
Selecting the newly added item, the contents behavior is re-attached, but not the one for the header.![image](https://github.com/microsoft/microsoft-ui-xaml/assets/10757343/aee29266-ee9e-4158-a43e-ba55280d6087)
Usercontrol:
Corresponding ViewModels:
Behavior for changing color depending on attached/detached:
Expected behavior
TabViewItem instances should not be reused when adding back a ViewModel instance that has been used previously. If it's part of some smart caching, I at least expect that behaviors should be reattached properly.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.5.4: 1.5.240607001
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response