microsoft / microsoft/microsoft-ui-xaml
Bug Report: App Crashes on Theme Change When Multiple Tabs Are Open in TabView
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
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.
here is my code for theme change
```
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;
}
```
i have tried to iterating through the tabs farme and update there Theme still no luck.
### Steps to reproduce the bug
1. create a WinUI app
2. implement TabView with settings page where you can change the theme to dark or light
3. change the theme while multiple tabs are open
4. now try to switch the tab it will throw an error
### Expected behavior
_No response_
### Screenshots
_No response_
### NuGet package version
None
### Windows version
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Start by reproducing the reported WinUI TabView scenario: open multiple tabs, change the application or system theme, then switch tabs. Inspect where the System.ArgumentException occurs during tab switching and compare behavior with the provided theme-change code; done means the scenario no longer crashes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100