Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting application theme on app constructor makes theme not working properly #1304

Open
kia-nasirzadeh opened this issue Jan 2, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@kia-nasirzadeh
Copy link

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

@kia-nasirzadeh kia-nasirzadeh added the bug Something isn't working label Jan 2, 2025
@kia-nasirzadeh
Copy link
Author

this can be solved by getting app theme on startup:

public partial class App : Application
{
    public App ()
    {
        Startup += App_Startup;
    }

    private void App_Startup(object sender, StartupEventArgs e)
    {
        var x = ApplicationThemeManager.GetAppTheme();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant