Search code examples
c#wpfwpf-controls

How to let a window use default style but not the UI framework (Lepoco WPFUI) style in WPF?


Recently, I added Lepoco WPFUI UI framework to my project, but I have one window that I want it to use the default style. In this case, I tried some ways but they did not work.
Here is my App.xaml:

<Application x:Class="Client_Window.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml"
             xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
             >
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                    <ui:ThemesDictionary Theme="Dark" />
                    <ui:ControlsDictionary />
                </ResourceDictionary.MergedDictionaries>
                <!--ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml" />
                <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml" />
            </ResourceDictionary.MergedDictionaries-->
        </ResourceDictionary>
    </Application.Resources>
</Application>

I tried the following:

Override the style of the window:

<Window x:Class="Client_Window.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:Client_Window"
        mc:Ignorable="d"
        Title="Login" Height="200" Width="400" ResizeMode="NoResize" Initialized="Window_Initialized">
    <Window.Resources>
        <!-- No merged dictionaries or different theme resources here -->
    </Window.Resources>
...

Set style to null:

I also tried to add Style="{x:Null}" to the <Window>.

Besides, I found some related problems like this one (Default WPF Styles with local Styles), but none of them can answer my question.

In this case, I am looking for a way to let a specific window not use the default style.


Addition:

After I tried @Krugs answer, it works, but it will also show a white scroll bar which used to not be there, and I do not want it to exist. The image

This can be solved by setting the width of the NavigationView to 100%.


Solution

  • You can remove the resource dictionary from your App.xaml

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ui:ThemesDictionary Theme="Dark"/>
                <ui:ControlsDictionary />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    
    <Application.Resources>
       
    </Application.Resources>

    And apply it to your Windows.Resources

            mc:Ignorable="d"
            xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
            Title="MainWindow" Height="450" Width="800">
        <Window.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ui:ThemesDictionary Theme="Dark"/>
                    <ui:ControlsDictionary />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Window.Resources>
        
        <Grid>
            
        </Grid>
    </Window>

    Note that you need to add [xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"] to each window to be able to use the resource, without the square brackets.