WPF 的 Windows 7 主题?

发布于 2024-08-18 05:33:26 字数 1745 浏览 4 评论 0原文

有没有办法让 WPF 应用程序看起来像在 Windows 7 上运行,即使它在 XP 上运行?我正在寻找某种可以粘贴的主题。我知道 Codeplex 上的主题项目 (https://archive.codeplex.com/?p=wpfthemes),但它缺乏对 DataGrid 的支持,而这是我迫切需要的。我在想也许 Windows 7 主题只是一个简单的移植,或者已经存在于某个文件中。


更新

使用@Lars Truijens idea,我能够获得主要控件的 Windows 7 外观,但不幸的是它不适用于 WPF Toolkit DataGrid 控件,我使用该控件需要。

DataGrid 看起来像 Aero 主题

Windows XP-look DataGrid

DataGrid 应该 看起来像这样

Windows 7-look DataGrid

因此,如果有人有任何想法,我仍在寻找解决此问题的方法。也许有人已经构建了涵盖 WPF 工具包控件的 Aero 主题扩展?再次强调,我们非常感谢您提供的任何信息。


更新 2 - DataGrid 问题已解决!

要让 Aero 主题与 DataGrid 或任何其他 WPF Toolkit 控件一起使用,您只需添加第二个 Aero 字典,因此您的 App.xaml 现在应该如下所示这。

<Application.Resources>
    ...
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary
                Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
            <ResourceDictionary
                Source="pack://application:,,,/WPFToolkit;component/Themes/Aero.NormalColor.xaml" />
            ...
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

另外,我建议关闭 DataGrid 控件中的网格线(因为它们看起来可怕):

<DataGrid GridLinesVisibility="None" ...>

Is there any way to make a WPF app look like it's running on Windows 7 even if it's running on XP? I'm looking for some kind of theme I can just paste in. I'm aware of the themes project on Codeplex (https://archive.codeplex.com/?p=wpfthemes), but it lacks support for DataGrid, which is something I critically need. I was thinking maybe the Windows 7 theme would just be an easy port, or exists in some file somewhere already.


Update

Using @Lars Truijens idea, I was able to get the Windows 7 look for the major controls, but unfortunately it did not work for the WPF Toolkit DataGrid control, which I need.

DataGrid looks like this with Aero theme

Windows XP-look DataGrid

DataGrid should look like this

Windows 7-look DataGrid

So, I'm still looking for a solution to this problem if anyone has any ideas. Maybe someone has built an extension to the Aero theme that covers the WPF toolkit controls? Again, any information you have is much appreciated.


Update 2 - DataGrid Problem solved!

To get the Aero theme to work with the DataGrid or any other WPF Toolkit controls, you just need to add a second Aero dictionary, so your App.xaml should now look like this.

<Application.Resources>
    ...
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary
                Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
            <ResourceDictionary
                Source="pack://application:,,,/WPFToolkit;component/Themes/Aero.NormalColor.xaml" />
            ...
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Also, I would recommend turning the gridlines off in your DataGrid controls (because they look horrible):

<DataGrid GridLinesVisibility="None" ...>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

唱一曲作罢 2024-08-25 05:33:26

WPF 在所有 Windows 版本上都附带标准 Windows 主题。例如,您可以通过以下步骤在 Windows XP 上使用 Aero 主题(Vista 和 Windows 7 使用):

  1. 根据需要将PresentationFramework.Aero 添加到应用程序的引用列表中 将
  2. 您的 App.xaml

从这里

<Application.Resources>
  <!-- Your stuff here -->
</Application.Resources>

编辑到此

<Application.Resources>
  <ResourceDictionary>
    <!-- Put your stuff here instead -->

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

源: http: //mrpmorris.blogspot.com/2008/05/using-vista-aero-theme-in-xp-wpf-apps.html

下面的其他替代方案。请务必根据需要将相应的程序集添加到应用程序的参考列表中。

<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 comes with the standard Windows themes on all Windows versions. For example, you can have the Aero theme (which Vista and Windows 7 use) on Windows XP with the following steps:

  1. Add PresentationFramework.Aero to your application's references list as a requires
  2. Edit your App.xaml

from this

<Application.Resources>
  <!-- Your stuff here -->
</Application.Resources>

to this

<Application.Resources>
  <ResourceDictionary>
    <!-- Put your stuff here instead -->

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

Source: http://mrpmorris.blogspot.com/2008/05/using-vista-aero-theme-in-xp-wpf-apps.html

Other alternatives below. Be sure to add the corresponding assembly to your application's reference list as a requires.

<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"/>
泪冰清 2024-08-25 05:33:26

Lars 的回答和 DanM 的更新的一项补充:

部署时,必须将 aero Dll 添加到安装目录。

您可以通过转到添加到引用中的PresentationFramework.Aero 属性并设置CopyLocal=True 来完成此操作。
然后,您必须使用您正在使用的任何部署工具(我喜欢 WIX...)并将其添加到已部署文件列表中。

One addition to Lars' answer and DanM's update:

When deploying, you must add the aero Dll to the installation dir.

You can do it by going to the properties of PresentationFramework.Aero you added to the references and setting CopyLocal=True .
Then, you'll have to go to whatever deployment tool you're using (I love WIX...) and add it to the list of deployed files.

ペ泪落弦音 2024-08-25 05:33:26

转到您的解决方案/项目属性,在“引用”下,您将能够添加对PresentationFramework.Aero的引用...
将其应用到您的代码中,它应该可以很好地工作

我希望我的回答对您有所帮助

Go to your solution/project properties, and under "References" you will be able to add a reference to PresentationFramework.Aero...
Apply it in your code and it should work nicely

I hope my answer helps you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文