microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.3k stars 676 forks source link

SelectedItem change is not reflected in TabView UI after adding item to TabItemsSource collection #3907

Closed MartinStrbak closed 1 year ago

MartinStrbak commented 3 years ago

Describe the bug When item is added to TabItemsSource collection and SelectedItem is changed to this newly added item, TabView UI does not reflect this (corresponding TabViewItem remains unselected).

Steps to reproduce the bug

  1. Run attached project Sample project.zip

  2. Clicking on first button works correctly - last tab is highlighted in UI if collection is unchanged SelectedItem = Items[Items.Count - 1];

  3. Clicking on second button does not work - selected item is not highlighted when I add item to collection right before setting SelectedItem Items.Add("New item"); SelectedItem = Items[Items.Count - 1];

Expected behavior TabViewItem corresponding to SelectedItem is selected (highlighted) in TabView UI.

Version Info NuGet package version: [Microsoft.WinUI 3.0.0-preview3.201113.0]

Windows app type: UWP Win32
Yes
Windows 10 version Saw the problem?
Insider Build (xxxxx)
20H2 (19042) Yes
May 2020 Update (19041)
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
Xbox
Surface Hub
IoT
StephenLPeters commented 3 years ago

@MartinStrbak do you know if this issue is unique to winui3 or if it is present in winui2 as well?

MartinStrbak commented 3 years ago

@StephenLPeters I tried in only on Win32 windows app type for WinUI (therefore WinUI3 only), as I am not familiar with UWP development.

I tried to replicate it on UWP with this result (see attached projects):

  1. UWP + WinUI2 (Nuget package Microsoft.UI.Xaml 2.5.0) - same result as in Win32 + WinUI3 (SelectedItem change does not work after adding new item)
  2. UWP + WinUI3 - same behavior as in Win32+WinUI3 (SelectedItem change does not work), but one additional issue occured - after adding new item to TabItemsSource collection, new tab is not displayed at all in TabView.

Hope this helps. Sample-UWP.zip

limefrogyank commented 3 years ago

For UWP with WinUI2, the preview build that is referenced in #3969 fixes this faulty behavior for me.

marcelwgn commented 3 years ago

@MartinStrbak Can you see if this also repos with the latest WinUI 2 prerelease?

@StephenLPeters If this doesn't repo with latest prerelease, could this be closed than since the changes would only have to be backported to the next WinUI 3 release?

sigmarsson commented 3 years ago

Is TabView.SelectedItem property expected to change upon a new tab is being added ? I do not see this happening.

techinessoverloaded commented 3 years ago

@StephenLPeters I tried in only on Win32 windows app type for WinUI (therefore WinUI3 only), as I am not familiar with UWP development.

I tried to replicate it on UWP with this result (see attached projects):

  1. UWP + WinUI2 (Nuget package Microsoft.UI.Xaml 2.5.0) - same result as in Win32 + WinUI3 (SelectedItem change does not work after adding new item)
  2. UWP + WinUI3 - same behavior as in Win32+WinUI3 (SelectedItem change does not work), but one additional issue occured - after adding new item to TabItemsSource collection, new tab is not displayed at all in TabView.

Hope this helps. Sample-UWP.zip

Yes, I too am having this same issue with UWP + WinUI 3. The New Tab is not at all displaying when a new item is added to the TabItemsSource ObservableCollection. But, it does get added to the collection. The Only problem is that it does not reflect the New Tab in the UI. Suppose, if Data Binding is not used and TabItems are added Manually, it is working perfectly. But, I want to use Data Binding. If anyone has a workaround for this problem, kindly share it.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

legistek commented 4 months ago

Still not working.

So do issues just get closed if Microsoft ignores them long enough? This framework is a nightmare.

sigmarsson commented 4 months ago

Opt for selectedindex and hack in the prop setter as a workaround...

legistek commented 4 months ago

Yeah thanks. That's really not the point though.