How to set the theme for a c# .net WPF application

一世执手 提交于 2019-12-11 19:53:57

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!