【发布时间】:2018-05-15 15:23:52
【问题描述】:
我注意到当有人从 Windows 10(我使用 Windows 7 制作)运行我的应用程序时,按钮变得未对齐,我认为发生这种情况的唯一原因是因为在运行时默认使用不同的主题在不同的操作系统上。
我将如何设置默认主题,而不是让它根据运行的操作系统进行选择?
很多其他类似的问题都引用了 app.xaml 文件?但我似乎没有这个,这是自动生成的还是我必须自己添加的?
【问题讨论】:
我注意到当有人从 Windows 10(我使用 Windows 7 制作)运行我的应用程序时,按钮变得未对齐,我认为发生这种情况的唯一原因是因为在运行时默认使用不同的主题在不同的操作系统上。
我将如何设置默认主题,而不是让它根据运行的操作系统进行选择?
很多其他类似的问题都引用了 app.xaml 文件?但我似乎没有这个,这是自动生成的还是我必须自己添加的?
【问题讨论】:
WPF 控件的默认模板在不同版本的 Windows 上看起来不同。
如果在 Visual Studio 中添加对 PresentationFramework.Aero.dll 的引用并将其 Copy Local 属性设置为 true,则可以通过将合并的 ResourceDictionary 添加到 App.xaml 中来应用 Windows 7 主题:
<Application ...>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
除了Aero,还有其他一些可用的主题(及其相应的程序集):
<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"/>
【讨论】: