Microsoft-ui-xaml: TabView SelectedItem Property Doesn't Set IsSelected Property of TabViewItems when ObservableCollection is Used

Created on 4 Apr 2020  路  6Comments  路  Source: microsoft/microsoft-ui-xaml

Describe the bug
Since our TabViewItems' Content property contains a Frame navigated to content, it turns out it is very expensive to manually create a TabViewItem and add it to TabView.TabItems, so instead we set the TabItemsSource property to an ObservableCollection<InstanceTabItem> to ensure (hopefully) items get disposed of when removed from the collection.

The problem with this approach is that programatically modifying the SelectedItem property to be set to one of the InstanceTabItems in the collection results in the TabView.SelectionChanged event NOT firing and the associated TabViewItem not being selected.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Add TabView to project
  2. Set TabView.TabItemsSource to an ObservableCollection full of data items that will be associated with a TabViewItem
  3. Attempt to change the TabView.SelectedItem property from code behind to one of the items in the ObservableCollection

Expected behavior
Logically, one would expect easy interpretation of tab data items (InstanceTabItem) in place of TabViewItems for the SelectedItem property to be consistent with other properties in the control that exclusively accept data items when an ObservableCollection is in use for the TabItemsSource.

Version Info

NuGet package version:
Microsoft.UI.Xaml 2.4.0-prerelease.200113001


| Windows 10 version | Saw the problem? |
| :--------------------------------- | :-------------------- |
| Insider Build (19041.172) | Yes |
| November 2019 Update (18363) | |
| May 2019 Update (18362) | |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) | |


| Device form factor | Saw the problem? |
| :-------------------- | :------------------- |
| Desktop | Yes |
| Mobile | |
| Xbox | |
| Surface Hub | |
| IoT | |

Additional context
This application is using this version of WinUI to work around other bugs, so unless changes were made recently that are relevant to this issue, it wouldn't make sense to upgrade/downgrade it as a troubleshooting step.

area-TabView help wanted team-Controls

All 6 comments

@ranjeshj @teaP FYI

I couldn't reproduce this on both WinUI 2.3.200213001 and the newest preview (2.4.0-prerelease.200322001).

Attached my test project below (project TabViewIsSelectedIssue in IssueCollection) to check back with @duke7553 in case I missunderstood one of their steps to reproduce:
IssueCollection.zip

@Felix-Dev Thank you for trying to repro. @duke7553 can you see if you can repro it with the latest pre-release bits ?

This also does not repro with the latest non prerelease version of WinUI (2.4). @duke7553 can you please look if the repro project should reproduce your issue?

@chingucoding Yes. I'll give this a try when I get another chance

I'll reopen this if the issue occurs again.

Was this page helpful?
0 / 5 - 0 ratings