NoWar
NoWar

Reputation: 37652

How to suppress WPF global app theme for User Control?

I have Expression Dark theme for the entire WPF application.

<Application x:Uid="Application_1" x:Class="MyShow.Player.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml"
             SessionEnding="App_SessionEnding" >
    <Application.Resources>
        <ResourceDictionary x:Uid="ResourceDictionary_1"  >
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary x:Uid="ResourceDictionary_3" Source="/Themes/ExpressionDark.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

What I have is that this Expression Dark applies to all User Controls ( public partial class UControl : UserControl).

What I want is to use totally different theme like Aero or something else for all WPF User Controls.

How I can do it?

Thank you!

Upvotes: 1

Views: 559

Answers (1)

Prathibha
Prathibha

Reputation: 166

Create a Startup event and set the theme in the Startup event Handler. That theme will be applied all user control in that solution. In your case.

//App.xaml

<Application x:Uid="Application_1" x:Class="MyShow.Player.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml"
             SessionEnding="App_SessionEnding"
             Startup="Application_Startup">

//App.xaml.cs

private void Application_Startup(object sender, StartupEventArgs e)
        {
            StyleManager.ApplicationTheme = new MetroTheme(); //Set your theme           
        }

Upvotes: 2

Related Questions