C# 我的Microsoft.Windows.Themes程序集在哪里?
我用XAML编写了一个用户控件,在它被编译成C之后,生成的C有以下行:C# 我的Microsoft.Windows.Themes程序集在哪里?,c#,.net,wpf,visual-studio,xaml,C#,.net,Wpf,Visual Studio,Xaml,我用XAML编写了一个用户控件,在它被编译成C之后,生成的C有以下行: using Microsoft.Windows.Themes; 现在会抛出一个错误: 命名空间中不存在类型或命名空间名称“Themes” “Microsoft.Windows”(是否缺少程序集引用?) 我想,既然我不能影响已编译C#的输出(没有什么可以从XAML中删除),我就把它添加为引用 但是,“添加引用”对话框不包含Microsoft.Windows.Themes。这不是.NET的一部分吗 下面是导致此问题的XAML用
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();
}
}
}
使用系统;
使用System.Windows.Controls;
命名空间GG.UserControls
{
///
///MainMenu.xaml的交互逻辑
///
公共部分类主菜单:UserControl
{
公共主菜单()
{
初始化组件();
}
}
}
下面是一个编译C#的示例:
#pragma校验和“.\..\..\..\UserControls\main menu.xaml”“{406ea660-64cf-4c82-b6f0-42D4817A799}”“5A85C5B165514165AD23641F944BC6”
//------------------------------------------------------------------------------
//
//这段代码是由一个工具生成的。
//运行时版本:4.0.30319.17020
//
//对此文件的更改可能会导致不正确的行为,如果
//重新生成代码。
//
//------------------------------------------------------------------------------
使用GG;
使用GG.UserControls;
使用Microsoft.Windows.Shell;
使用Microsoft.Windows.Themes;// Microsoft.Windows.Themes
可在特定于主题的PresentationFramework程序集中找到。根据XAML中引用的对象,您需要添加对以下对象之一的引用:
- PresentationFramework.Aero.dll
- PresentationFramework.AeroLite.dll
- PresentationFramework.Classic.dll
- PresentationFramework.Luna.dll
- PresentationFramework.Royale.dll
“您的XAML中引用了什么”?我没有提到任何这样的事情。我应该选哪一个?稍后我会在我的问题中发布我的XAML。嗯,我在一个新的WPF项目中将您的代码放在一个新的用户控件中,它不会为我生成那个using语句。using语句在代码中的具体位置出现了?我附上了编译好的XAML->C#代码。它使用
显示。我尝试了干净的解决方案,然后重新构建解决方案,没有任何区别。我怀疑您的菜单中有包含特定主题元素的内容。尝试只添加对PresentationFramework.Aero.dll的引用,看看会发生什么。在我添加了PresentationFramework.Aero.dll
后工作正常。嗯。我正在使用reflector在PresentationFramework.dll下搜索,我似乎找不到任何主题。dll它们的物理位置在哪里?
#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;
}
}
}