0

I has been noticed that when someone runs my application from windows 10 (I made it using windows 7) that buttons become unaligned, the only reason I can think for this happening is because of the different theme being defaulted to while being ran on the different operating systems.

How would I go about setting the default theme rather than allow it to choose depending on the operating system it is running on?

A lot of other similar questions reference a app.xaml file? but i don't seem to have this, is this auto-generated or something I would have to add myself?

C. Dodds
  • 325
  • 3
  • 12
  • Possible duplicate here [WPF: Windows 7 vs Windows 10 Appearance](https://stackoverflow.com/questions/38830996/wpf-windows-7-vs-windows-10-appearance) and possible solution here [How to force to have Windows 7 theme on Windows Server 2003 for a WPF application](https://stackoverflow.com/questions/12435154/how-to-force-to-have-windows-7-theme-on-windows-server-2003-for-a-wpf-applicatio/12437878#12437878) – rickvdbosch May 15 '18 at 15:30

1 Answers1

5

The default templates of the WPF controls look different on different versions of Windows.

If you add a reference to PresentationFramework.Aero.dll and set its Copy Local property to true in Visual Studio, you can apply a Windows 7 theme your application by adding a merged ResourceDictionary into your App.xaml:

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

Besides Aero, there are some other themes (and their corresponding assemblies) available as well:

<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Classic;component/themes/Classic.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Royale;component/themes/Royale.NormalColor.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna.Homestead;component/themes/Luna.Homestead.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna.Metallic;component/themes/Luna.Metallic.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Zune;component/themes/Zune.NormalColor.xaml"/>
mm8
  • 163,881
  • 10
  • 57
  • 88
  • My WPF doesn't seem to have an App.xaml? Where would I find this file – C. Dodds May 15 '18 at 15:34
  • @C.Dodds In the root of your main WPF project. I think you need to set its build action to "ApplicationDefinition" in the file properties. – ckuri May 15 '18 at 15:57
  • If you create a WPF application project in Visual Studio, it automatically creates an App.xaml file for you in the root folder of the project. – mm8 May 16 '18 at 07:41