lepoco / lepoco/wpfui

getting application theme on app constructor makes theme not working properly

Open
#1,304 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
9.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

// comment following line and everything works, but having that line in application constructor make themes not working properly
var makebug = ApplicationThemeManager.GetAppTheme();

To Reproduce

to reproduce this just make a new wpf application (use .net-9 and wpf-ui 4.0.0-rc.3) and fill out following files like this:


App.xaml:
<Application x:Class="BugReportProject.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:BugReportProject"
             xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ui:ThemesDictionary Theme="Dark" />
                <ui:ControlsDictionary />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

App.xaml.cs:
using System.Configuration;
using System.Data;
using System.Windows;
using Wpf.Ui.Appearance;

namespace BugReportProject
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App ()
        {
            // comment following line and everything works, but having that line in application constructor make themes not working properly
            var makebug = ApplicationThemeManager.GetAppTheme();
        }
    }

}


MainWindow.xaml:
<ui:FluentWindow
    x:Class="BugReportProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:BugReportProject"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800"
    xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml">
    <StackPanel>
        <ui:TitleBar Title="WPF UI"/>
        <ui:Card Margin="8">
            <ui:Button Name="changeBtn" Content="change theme" Icon="{ui:SymbolIcon Fluent24}" />
        </ui:Card>
    </StackPanel>
</ui:FluentWindow>

MainWindow.xaml.cs:
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;

namespace BugReportProject
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : FluentWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            changeBtn.Click += (s, e) =>
            {
                if (ApplicationThemeManager.GetAppTheme() == ApplicationTheme.Dark) ApplicationThemeManager.Apply(ApplicationTheme.Light);
                else ApplicationThemeManager.Apply(ApplicationTheme.Dark);
            };
        }
    }
}
Expected behavior

by clicking on changeBtn theme should switch between dark and light, but everything stucks if following line exists in App class constructor:
var makebug = ApplicationThemeManager.GetAppTheme();

Screenshots

No response

OS version

Microsoft windows
version 21H2 (OS Build 22000.3260)

.NET version

net9.0-windows

WPF-UI NuGet version

wpf-ui 4.0.0-rc.3

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the constructor in App.xaml.cs and compare its ApplicationThemeManager.GetAppTheme() call with the theme-switching handler in MainWindow.xaml.cs. Reproduce the project using App.xaml, MainWindow.xaml, .NET 9, WPF UI 4.0.0-rc.3, and Windows 21H2. Done means clicking changeBtn switches reliably between dark and light themes even when the constructor call is present.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.