Bug Report: App Crashes on Theme Change When Multiple Tabs Are Open in TabView
Which version of the app?
WinUI 3 Gallery
Description
When multiple tabs are open in a TabView and the application theme or system theme is changed (either manually or automatically), the application crashes with the following error:
System.ArgumentException: Value does not fall within the expected range.
This happens both in custom applications and in the official WinUI 3 Gallery example provided by Microsoft.
🔁 Reproduction Steps
In WinUI 3 Gallery:
Open the TabView sample.
Add 3–4 tabs using the "Add Tab" button.
Switch the theme via the app’s theme toggle or through system settings.
The app crashes.
In Custom Application (Confirmed):
Create a TabView, where each TabViewItem hosts a Frame that navigates to a page.
Open multiple tabs with different pages.
Change App.RequestedTheme or toggle system theme.
Application crashes with the same exception.
Changing the theme should cause all visual elements to update without crashing the app. what i could tell of now is child elements of the frame doesnt update there theme no matter what there ActualTheme stays the same.
Screenshots
No response
Windows version
Windows 11 24H2 (26100)
Additional context
No response
Hi @muni20! I followed these steps but I couldn't reproduce the crash.
- Launch the WinUI 3 Gallery app (v2.4.2.0).
- Navigate to the
TabViewpage. - Scroll up to the first example labeled "A TabView with support for adding, closing, and rearranging".
- Add 5 tabs by clicking the '+' button.
- Click the
Toggle Themebutton.
Can you reconfirm the steps to reproduce the crash?
I couldn't reproduce the bug; can you provide more information?
Hi @AndrewKeepCoding @Zakariathr22 open WinUI 3 Gallery app
Navigate to TabView section
open Complete TabView windowing sample
now while the window is open try to change the system theme or create a new project implement TabView and then while multiple Tabs are open try to change the theme be it system theme or AppTheme and then try to switch the tabs app will crash
in my app i have tried to change the theme using
try
{
var currentTheme = (FrameworkElement)App.m_window.Content;
if (App.m_window.Content is FrameworkElement rootElement)
{
rootElement.RequestedTheme = param;
TitleBarHelper.UpdateTitleBar(param);
var ThemeSaved = await _settings.SaveSettings(AppConstants.Theme_Key, param.ToString());
if (ThemeSaved)
{
infoBar.Severity = InfoBarSeverity.Success;
infoBar.Title = "Theme Changed";
infoBar.Message = $"Theme has been changed to {param.ToString()}.";
infoBar.IsIconVisible = true;
infoBar.IsOpen = true;
await Task.CompletedTask;
}
}
}
catch (Exception ex)
{
infoBar.Severity = InfoBarSeverity.Error;
infoBar.Title = "Error";
infoBar.Message = $"An error occurred while changing the theme: {ex.Message}";
infoBar.IsIconVisible = true;
infoBar.IsOpen = true;
await Task.CompletedTask;
}
and i have tried to iterating through the tabs farme and update there Theme still no luck.
@muni20 If this is reproducible on your app, I recommend posting an issue on Microsoft/microsoft-xaml-ui instead of this repo.
@AndrewKeepCoding i will do that, thanks, but winui 3 gallery also have this bug where if you follow my steps app crashes instantly.
I believe this issue is addressed in PR #1664.
nope tried it
2.6.0 has serious issues with:
Switching tabs and then just hovering over the main window crashes the app.
2.6.0 has serious issues with:
Switching tabs and then just hovering over the main window crashes the app.
yes, and i m still not able to fix my problem yet 💯
