我的Microsoft.Windows.Themes程序集在哪里?

15

我在XAML中编写了一个用户控件,编译后生成的C#代码里有这一行:

using Microsoft.Windows.Themes;

现在会抛出一个错误:

类型或命名空间名称"Themes"在命名空间"Microsoft.Windows"中不存在(是否缺少程序集引用?)

我认为由于我无法影响已编译的C#的输出(XAML中没有什么可以删除的),因此我只需将其作为引用添加即可。

但是,添加引用对话框中不包含Microsoft.Windows.Themes。这不是.NET的一部分吗?

以下是导致此问题的示例XAML用户控件:

<UserControl x:Class="GG.UserControls.MainMenu"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <StackPanel>
        <Menu VerticalAlignment="Top" Background="{x:Null}">
            ... // Just static menu items.
        </Menu>
    </StackPanel>

</UserControl>

还有它的 C# 后台代码:

using System;
using System.Windows.Controls;

namespace GG.UserControls
{
    /// <summary>
    /// Interaction logic for MainMenu.xaml
    /// </summary>
    public partial class MainMenu : UserControl
    {
        public MainMenu()
        {
            InitializeComponent();
        }
    }
}

以下是C#编译代码的示例:

#pragma checksum "..\..\..\..\UserControls\MainMenu.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "5A85C5B16565514165AD23641F944BC6"
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.17020
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using GG;
using GG.UserControls;
using Microsoft.Windows.Shell;
using Microsoft.Windows.Themes; // <---- WTF?
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;


namespace GG.UserControls {


    /// <summary>
    /// ChangesetHistory
    /// </summary>
    public partial class MainMenu : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector {

        private bool _contentLoaded;

        /// <summary>
        /// InitializeComponent
        /// </summary>
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        public void InitializeComponent() {
            if (_contentLoaded) {
                return;
            }
            _contentLoaded = true;
            System.Uri resourceLocater = new System.Uri("/GG;component/usercontrols/mainmenu.xaml", System.UriKind.Relative);

            #line 1 "..\..\..\..\UserControls\MainMenu.xaml"
            System.Windows.Application.LoadComponent(this, resourceLocater);

            #line default
            #line hidden
        }

        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
            this._contentLoaded = true;
        }
    }
}

我正在使用反编译器在PresentationFramework.dll下搜索,但似乎找不到任何主题的.dll文件。它们物理上位于哪里? - eran otzap
1个回答

31

Microsoft.Windows.Themes 是在特定主题的 PresentationFramework 组件中找到的。根据你的 XAML 引用的组件,你需要添加以下其中一个引用:

  • PresentationFramework.Aero.dll
  • PresentationFramework.AeroLite.dll
  • PresentationFramework.Classic.dll
  • PresentationFramework.Luna.dll
  • PresentationFramework.Royale.dll

1
添加了 PresentationFramework.Aero.dll 后,功能正常。嗯。 - Tower
我正在使用反编译器在PresentationFramework.dll下搜索,但似乎找不到任何主题的.dll文件。它们物理上位于哪里? - eran otzap
谢谢您的反馈。在使用VS2012时,Windows.Themes可以正常工作,但在升级到VS2013之后出现了问题(这是最糟糕的错误)。 - New Bee
@Tower,我在哪里可以找到PresentationFramework.Aero.dll这个物理文件? - eran otzap
好的,我没有能够在物理上找到它,但是你可以从这里下载它: http://www.dllme.com/dll/download/6959/PresentationFramework.Aero.dll - eran otzap
显示剩余6条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接