【问题标题】:How to set the theme for a c# .net WPF application如何为 c# .net WPF 应用程序设置主题
【发布时间】:2018-05-15 15:23:52
【问题描述】:

我注意到当有人从 Windows 10(我使用 Windows 7 制作)运行我的应用程序时,按钮变得未对齐,我认为发生这种情况的唯一原因是因为在运行时默认使用不同的主题在不同的操作系统上。

我将如何设置默认主题,而不是让它根据运行的操作系统进行选择?

很多其他类似的问题都引用了 app.xaml 文件?但我似乎没有这个,这是自动生成的还是我必须自己添加的?

【问题讨论】:

标签: c# .net wpf themes


【解决方案1】:

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"/>

【讨论】:

  • 我的 WPF 似乎没有 App.xaml?我在哪里可以找到这个文件
  • @C.Dodds 在主 WPF 项目的根目录中。我认为您需要在文件属性中将其构建操作设置为“ApplicationDefinition”。
  • 如果您在 Visual Studio 中创建 WPF 应用程序项目,它会自动在项目的根文件夹中为您创建一个 App.xaml 文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-07
  • 2014-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多