lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.4k stars 717 forks source link

Creating a new window object breaks the theme switcher #866

Open Byolock opened 9 months ago

Byolock commented 9 months ago

Describe the bug

Creating a new window object in the MainWindow class makes the theme Switcher work incorrectly. The other design is only applied partially. If the starting theme is the Dark Theme this means the background stays dark and some parts of the user controls get brighter but not all. If the starting theme is the Light Theme this means the background stays in white and all user controls get white, essentially rendering them invisible.

To Reproduce

  1. Setup a new WPF Project
  2. Make the MainWindow class a type of FluentWindow
  3. Create a button and method to switch from dark theme to light and the other way :
    
    if (Wpf.Ui.Appearance.ApplicationThemeManager.GetAppTheme() == Wpf.Ui.Appearance.ApplicationTheme.Dark)
    {
    Wpf.Ui.Appearance.ApplicationThemeManager.Apply(
    Wpf.Ui.Appearance.ApplicationTheme.Light    // Theme type
    );

} else if (Wpf.Ui.Appearance.ApplicationThemeManager.GetAppTheme() == Wpf.Ui.Appearance.ApplicationTheme.Light) { Wpf.Ui.Appearance.ApplicationThemeManager.Apply( Wpf.Ui.Appearance.ApplicationTheme.Dark // Theme type );

}

4. create a new FluentWindow in the project named window1
5. start the application and hit the button to change the theme. It should work as expected.
6. create a object for this newly created windows directly inside the MainWindow class:

public partial class MainWindow : FluentWindow { private Window1 _window = new();

private void some_method(){
}

}

7. start the application and hit the button to change the theme. It shouldn't work as expected.

### Expected behavior

A click on the button should apply the new theme on the windows and every user control correctly.

### Screenshots

If i try to switch from Light to Dark theme:

![switch_to_dark_theme](https://github.com/lepoco/wpfui/assets/25748003/f9594184-ee48-489d-b3c7-126ad275bac9)

If i try to switch from Dark to Light theme:

![switch_to_light_theme](https://github.com/lepoco/wpfui/assets/25748003/4010b1c2-5b2b-4ce9-893b-403f4197d4bf)

### OS version

Windows 10

### .NET version

.Net 8.0

### WPF-UI NuGet version

3.0.0-preview.12

### Additional context

simply removing ` private Window1 _window = new();` fixes this behavior. If the window gets declared inside a method of the MainWindow class, the problem disappears too. But only for the MainWindow.
This code : 
    private void Button_Click(object sender, RoutedEventArgs e)
    {

        Window1 _window = new();
        _window.Show();

    }


will make MainWindow work as expected, but if the Theme is changed the new `_window` does now show the behavior shown in the screenshots above.
SamKr commented 6 months ago

I'm having the same issue when opening a second FluentWindow; it doesn't follow theme changes. Did you find a solution @Byolock, or what are we missing @pomianowski ?

SamKr commented 6 months ago

Workaround: https://github.com/lepoco/wpfui/issues/488#issuecomment-1519536889

Byolock commented 6 months ago

I did not find a solution. I paused my project and hoped it would have been fixed by the time I would continue on my project. Otherwise I planned on going back to the ui framework I used before migrating to this one.

I've seen you posted a workaround. I'll try that one out, should be good enough for my use case.

SamKr commented 6 months ago

Let me know if you need help with the implementation