简体   繁体   中英

WPF OS dependent theme: Win XP = Aero / Win 7, 8, 8.1 = AeroLite

I have to develop an application in WPF and C#, using MVVM-pattern, that should run on Windows XP, 7, 8, 8.1. Besides my development system bases on Windows 8.1. So far I developed my application in .NET-framework 4.0 and my application runs as desired on all OS's. But now the problem is, that the theme differs from OS to OS, so I tried this:

Code from 'App.xaml'

<Application x:Class="MyApplication.App"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Application.Resources>
        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
                <ResourceDictionary Source="/PresentationFramework.AeroLite;component/themes/AeroLite.NormalColor.xaml"/>
            </ResourceDictionary.MergedDictionaries>

        </ResourceDictionary>
    </Application.Resources>

</Application>

I added references of: PresentationFramework.Aero, and PresentationFramework.AeroLite to my project and changed the reference-properties from "Copy to Local = False" to "Copy to Local = True"

The good thing:

Now on Windows 7, 8, 8.1 the Windows 8 theme will apply.

The bad thing:

But on Windows XP the application doesn't run, because the OS wants to apply the AeroLite-theme, which isn't probably supported.

So what can I do, to apply:

  • AeroLite-theme on Windows 7, 8, 8.1 ?

  • Aero-them on Windows XP ?

Is it possible to apply the AeroLite-theme although on Windows XP anyway?

I've got the solution:

Changed this in: App.xaml.cs

Version windowsVistaVersion = new Version(6, 0, 0000, 0);

if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version >= windowsVistaVersion)
{
    App.Current.Resources.Source = new Uri("/PresentationFramework.AeroLite;component/themes/AeroLite.NormalColor.xaml", uriKind: UriKind.Relative);
}

else if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version < windowsVistaVersion)
{
    App.Current.Resources.Source = new Uri("/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml", uriKind: UriKind.Relative);
}

Changed App.xaml to:

<Application x:Class="MyApplication.App"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

</Application>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM