WPF 的 Windows 7 主题? [英] Windows 7 theme for WPF?

查看:21
本文介绍了WPF 的 Windows 7 主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以让 WPF 应用程序看起来像是在 Windows 7 上运行,即使它在 XP 上运行?我正在寻找某种我可以粘贴的主题.我知道 Codeplex 上的主题项目 (

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

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

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

DataGrid should look like this

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

解决方案

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

这篇关于WPF 的 Windows 7 主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆