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.09k stars 671 forks source link

Theming broken in v2.1.0 #919

Open Reeceeboii opened 5 months ago

Reeceeboii commented 5 months ago

Describe the bug

The theming is completely broken for me, I'm seeing some very strange behaviour.

App.xaml - load in dictionaries

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ui:ThemesDictionary />
            <ui:ControlsDictionary />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

MainWindow.xaml - define main window with dummy content

<ui:UiWindow x:Class="Test.Client.Views.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:Test.Client.Views"
        xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" 
        mc:Ignorable="d"
        Title="Test" Height="1200" Width="1800">

    <Grid>
        <TextBlock Text="hello world" />
    </Grid>

</ui:UiWindow>

MainWindowViewModel.cs - basic ViewModel for this example so I can apply some styles

public class MainWindowViewModel : ObservableObject
{
    public MainWindowViewModel()
    {
        Theme.Apply(ThemeType.Dark, BackgroundType.Mica, true);
    }
}

So with the above:

Theme.Apply(ThemeType.Dark, BackgroundType.Mica, true);

makes the window completely black, mica background not working

image

Theme.Apply(ThemeType.Light, BackgroundType.Mica, true);

window still black despite the light theme, even more confusingly, the text has now vanished

image

Theme.Apply(ThemeType.Dark, BackgroundType.Acrylic, true);

changing to acrylic has no impact

image


I have tried different combinations of the above, all seem to be broken in some way. As far as I'm aware I have followed the documentation and have my application configured in the correct manner. I am able to place controls from the library onto my window so it's all talking correctly, it just seems to be the theming that's falling over.

To Reproduce

Install library as above, and produce minimal WPF application. Attempt to apply theming, see broken results.

Expected behavior

Theming applies correctly and background styles work.

Screenshots

See bug report.

OS version

Windows 23H2 (OS Build 22631.3007)

.NET version

.NET 8.0

WPF-UI NuGet version

2.1.0

Additional context

Not sure if it will help pinpointing the issue, but you can see that the window title is also gone in all examples. If I remove the library, it returns.

frostybee commented 5 months ago

Hello @Reeceeboii,

Have you tried the Wpf.Ui.Demo.Mvvm sample? Changing the theme should be done through the Wpf.Ui.Appearance.ApplicationThemeManager and not like how you did it.

I suggest that you clone the repository and run the Wpf.Ui.Demo.Mvvm sample. You will be able to change the theme in that sample from the settings menu as shown below: image

Also, have a look at the OnChangeTheme method that can be found in SettingsViewModel.cs,

image

I am not sure how you created the project for your application, but you should install the Visual Studio 2022 Extension for WPF UI https://wpfui.lepo.co/documentation/extension.html and create a project by following the steps shown on that Webpage.

Hope this helps.

Reeceeboii commented 5 months ago

@frostybee

Thanks for the response. I will check out the demo code - granted I didn't actually look, I was going by the theming documentation at https://wpfui.lepo.co/documentation/themes.html that shows the ability to change on the fly using the code I tried above, but it definitely doesn't work for me.

I didn't use one of the template projects as I often structure my projects differently, but the manual setup is relatively short and everything else works (controls etc...), just not the theming.

frostybee commented 5 months ago

As far as I know, there has been some refactoring done on the changing the theme logic: ThemeType has been replaced by Application theme in ApplicationTheme in newer versions > 2.1.0

You may want to use the latest (or a preview) version as it contains bug fixes.

Jay-o-Way commented 1 month ago

Hey @lepoco, @pomianowski - You have a couple of issues regarding the Mica effect and theme switching. Might be a few duplicates, but would you be so kind to look into these issues? I see a lot of comments in different repositories about them. Thanks!