WinUI-Gallery icon indicating copy to clipboard operation
WinUI-Gallery copied to clipboard

Bug Report: App Crashes on Theme Change When Multiple Tabs Are Open in TabView

Open muni20 opened this issue 7 months ago • 9 comments

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

muni20 avatar Apr 30 '25 23:04 muni20

Hi @muni20! I followed these steps but I couldn't reproduce the crash.

  1. Launch the WinUI 3 Gallery app (v2.4.2.0).
  2. Navigate to the TabView page.
  3. Scroll up to the first example labeled "A TabView with support for adding, closing, and rearranging".
  4. Add 5 tabs by clicking the '+' button.
  5. Click the Toggle Theme button.

Can you reconfirm the steps to reproduce the crash?

AndrewKeepCoding avatar May 01 '25 08:05 AndrewKeepCoding

I couldn't reproduce the bug; can you provide more information?

Zakariathr22 avatar May 01 '25 09:05 Zakariathr22

Hi @AndrewKeepCoding @Zakariathr22 open WinUI 3 Gallery app

Navigate to TabView section

Image

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 avatar May 01 '25 10:05 muni20

@muni20 If this is reproducible on your app, I recommend posting an issue on Microsoft/microsoft-xaml-ui instead of this repo.

AndrewKeepCoding avatar May 02 '25 02:05 AndrewKeepCoding

@AndrewKeepCoding i will do that, thanks, but winui 3 gallery also have this bug where if you follow my steps app crashes instantly.

muni20 avatar May 02 '25 07:05 muni20

I believe this issue is addressed in PR #1664.

Zakariathr22 avatar May 02 '25 09:05 Zakariathr22

nope tried it

muni20 avatar May 02 '25 19:05 muni20

2.6.0 has serious issues with: Image

Switching tabs and then just hovering over the main window crashes the app.

Balkoth avatar Jun 02 '25 08:06 Balkoth

2.6.0 has serious issues with: Image

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 💯

muni20 avatar Jun 03 '25 00:06 muni20