问题
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?
回答1:
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"/>
来源:https://stackoverflow.com/questions/50353916/how-to-set-the-theme-for-a-c-sharp-net-wpf-application