代码之家  ›  专栏  ›  技术社区  ›  devuxer

WPF的Windows 7主题?

  •  38
  • devuxer  · 技术社区  · 16 年前

    有没有办法让WPF应用看起来像是在Windows7上运行的,即使它是在XP上运行的?我在找一些我可以粘贴的主题。我知道codeplex上的主题项目( http://www.codeplex.com/wpfthemes ),但它缺少对 datagrid 的支持,这是我急需的东西。我想Windows7主题可能只是一个简单的端口,或者已经存在于某个文件中了。如果您有任何信息(即使是坏消息),我们将不胜感激。

    更新

    使用@lars truijens的想法,我可以让Windows 7查找主要控件,但不幸的是,它不适用于wpf工具包 datagrid control,which I need.

    datagrid looks like this with aero theme

    datagrid. should. look like this.

    所以,如果有人有任何想法,我仍然在寻找解决这个问题的方法。也许有人已经为涵盖WPF工具包控件的Aero主题构建了一个扩展?同样,我们非常感谢您提供的任何信息。

    更新2-问题解决!

    要使Aero主题与WPF工具包控件一起工作,只需添加第二个Aero字典,因此您的a p p.xaml现在应该如下所示。

    应用程序资源 … <资源字典> <resourceDictionary.mergedDictionaries> <资源字典 source=“/presentationframework.aero;组件/themes/aero.normalColor.xaml”/> <资源字典 source=“pack://application:,,/wpftoolkit;component/themes/aero.normalcolor.xaml”/> … </resourcedictionary.mergeddictionaries> </resourcedictionary> </application.resources>

    
    

    另外,我建议您在datagridcontrols(因为它们看起来很恐怖)中关闭网格线:

    <datagrid gridlinesvisibility=“none”…>
    < /代码> <可以直接粘贴。我知道CodePlex的主题项目(http://www.codeplex.com/wpfthemes但是它缺乏对DataGrid这是我迫切需要的。我想Windows7主题可能只是一个简单的端口,或者已经存在于某个文件中了。你所掌握的任何信息(即使是坏消息)都会非常感谢。

    更新

    使用@lars truijens的想法,我可以让Windows7查找主要控件,但不幸的是,它不适用于WPF工具包。数据网格我需要控制。

    数据报ID看起来像是航空主题

    Windows XP-look DataGrid

    数据网格应该看起来像这样

    Windows 7-look DataGrid

    所以,如果有人有任何想法,我仍然在寻找解决这个问题的方法。也许有人已经为涵盖WPF工具包控件的Aero主题构建了一个扩展?再次感谢您提供的任何信息。

    更新2-问题解决!

    为了让Aero主题与WPF工具包控件一起工作,您只需要添加第二个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 GridLinesVisibility="None" ...>
    
    2 回复  |  直到 8 年前
        1
  •  50
  •   Lars Truijens    16 年前

    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"/>
    
        2
  •  4
  •   GuYsH    14 年前

    Lars的回答和Danm的更新增加了一个:

    部署时,必须将Aero dll添加到安装目录中。

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

    推荐文章