You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When removing non-selected items from a TabView the currently selected TabViewItem recieves an Unloaded event once for each removed tab.
Steps to reproduce the bug
Bind the TabItemsSource of a TabView to an ObservableCollection with some items in it.
Trigger a method that removes items from the collection that are not currently selected.
The selected tab is unloaded multiple times.
Example code (not full):
public class MainWindowViewModel : INotifyPropertyChanged
{
public ObservableCollection<ItemViewModel> Items { get; } = [];
public ObservableCollection<ItemViewModel> TabItems { get; } = [];
public ItemViewModel? CurrentTabItem { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public void AddTabs()
{
CurrentTabItem = null;
TabItems.Clear();
TabItems.Add(new ItemViewModel { Name = "ViewModel A" });
TabItems.Add(new ItemViewModel { Name = "ViewModel B" });
TabItems.Add(new ItemViewModel { Name = "ViewModel C" });
TabItems.Add(new ItemViewModel { Name = "ViewModel D" });
CurrentTabItem = TabItems[0];
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentTabItem)));
Items.Clear();
foreach (var item in TabItems) {
Items.Add(item);
}
}
public void RemoveAllButCurrent()
{
foreach (var item in TabItems.ToList())
{
if (item != CurrentTabItem)
{
TabItems.Remove(item);
}
}
}
}
public class ItemViewModel : INotifyPropertyChanged
{
public required string Name { get; set; }
public int Loaded { get; private set; }
public int Unloaded { get; private set; }
public void Load()
{
Loaded++;
OnPropertyChanged(nameof(Loaded));
}
public void Unload()
{
Unloaded++;
OnPropertyChanged(nameof(Unloaded));
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
}
Initial state. Note that the selected tab has been unloaded one time, does not seem correct to me.
After selecting each tab once.
After removing all non-selected tabs. Note that ViewModel D reports 3 extra unloaded events. It has also been loaded once again. But the loaded event comes first, and the three unloaded events come afterwards.
NuGet package version
WinUI 3 - Windows App SDK 1.5.5: 1.5.240627000
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response
The text was updated successfully, but these errors were encountered:
Describe the bug
When removing non-selected items from a TabView the currently selected TabViewItem recieves an Unloaded event once for each removed tab.
Steps to reproduce the bug
Example code (not full):
Expected behavior
No response
Screenshots
Initial state. Note that the selected tab has been unloaded one time, does not seem correct to me.
After selecting each tab once.
After removing all non-selected tabs. Note that ViewModel D reports 3 extra unloaded events. It has also been loaded once again. But the loaded event comes first, and the three unloaded events come afterwards.
NuGet package version
WinUI 3 - Windows App SDK 1.5.5: 1.5.240627000
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response
The text was updated successfully, but these errors were encountered: