2012-03-11 38 views
12

Tôi đã viết một điều khiển người dùng trong XAML và sau khi nó được biên dịch vào C# kết quả C# có dòng này:Lắp ráp Microsoft.Windows.Themes của tôi ở đâu?

using Microsoft.Windows.Themes; 

nào ném một lỗi ngay bây giờ:

Loại hoặc namespace tên 'Chủ đề' không tồn tại trong không gian tên 'Microsoft.Windows' (bạn có thiếu tham chiếu lắp ráp không?)

Tôi figured vì tôi không thể ảnh hưởng đến đầu ra của C# biên dịch (không có gì để xóa e từ XAML), tôi chỉ thêm nó làm Tham chiếu.

Tuy nhiên, hộp thoại Thêm tham chiếu không chứa Microsoft.Windows.Themes. Đây có phải là một phần của .NET không?

Dưới đây là một ví dụ điều khiển người dùng XAML gây vấn đề này:

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

Và C# code đằng sau nó:

using System; 
using System.Windows.Controls; 

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

Dưới đây là một ví dụ về biên soạn 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; 
     } 
    } 
} 
+0

tôi đang tìm kiếm dưới PresentationFramework.dll sử dụng phản xạ, tôi không thể có vẻ để xác định vị trí bất kỳ của các chủ đề .dlls, nơi họ có vị trí thực tế? –

Trả lời

29

Microsoft.Windows.Themes được tìm thấy trong các hội thảo PresentationFramework theo chủ đề cụ thể. Bạn sẽ muốn thêm một tham chiếu đến một trong những điều sau đây tùy thuộc vào cái nào được tham chiếu trong XAML của bạn:

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

"Tham chiếu trong XAML của bạn" là gì? Tôi không có tham chiếu đến bất kỳ điều như vậy. Tôi nên chọn cái nào? Tôi sẽ đăng XAML của tôi trong câu hỏi của tôi trong một giây. – Tower

+0

Hmm, tôi đã bỏ mã của bạn trong một điều khiển người dùng mới trong một dự án WPF mới và nó không tạo ra tuyên bố sử dụng đó cho tôi. Mã lệnh của bạn xuất hiện ở đâu? – BoltClock

+0

Tôi đã đính kèm mã XAML -> C# đã biên dịch. Nó cho thấy 'sử dụng'. Tôi đã thử giải pháp sạch và sau đó xây dựng lại giải pháp mà không có sự khác biệt. – Tower

Các vấn đề liên quan