Where is my Microsoft.Windows.Themes assembly?
Microsoft.Windows.Themes
is found in the theme-specific PresentationFramework assemblies. You'll want to add a reference to one of the following depending on which one is referenced in your XAML:
- PresentationFramework.Aero.dll
- PresentationFramework.AeroLite.dll
- PresentationFramework.Classic.dll
- PresentationFramework.Luna.dll
- PresentationFramework.Royale.dll
Tower
Updated on June 15, 2022Comments
-
Tower almost 2 years
I wrote a user control in XAML and after it gets compiled into C# the resulting C# has this line:
using Microsoft.Windows.Themes;
Which throws an error now:
The type or namespace name 'Themes' does not exist in the namespace 'Microsoft.Windows' (are you missing an assembly reference?)
I figured since I can't affect the output of compiled C# (there's nothing to remove from XAML), I would just add that as Reference.
However, the Add Reference dialog does not contain
Microsoft.Windows.Themes
. Is this not part of .NET?Here's an example XAML user control that causes this problem:
<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>
And C# code behind it:
using System; using System.Windows.Controls; namespace GG.UserControls { /// <summary> /// Interaction logic for MainMenu.xaml /// </summary> public partial class MainMenu : UserControl { public MainMenu() { InitializeComponent(); } } }
Here's an example of compiled 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; } } }
-
Tower about 12 years"What's referenced in your XAML"? I have no references to any such things. Which one should I pick? I'll post my XAML in my question in a second.
-
BoltClock about 12 yearsHmm, I dropped your code in a fresh user control in a fresh WPF project and it doesn't produce that using statement for me. Where exactly in your code does the using statement appear?
-
Tower about 12 yearsI attached the compiled XAML -> C# code. It shows the
using
. I've tried Clean Solution and then Rebuild Solution without difference. -
BoltClock about 12 yearsI suspect there's something within your
Menu
that contains theme-specific elements. Try just adding a reference to PresentationFramework.Aero.dll and see what happens. -
Tower about 12 yearsWorks fine after I added
PresentationFramework.Aero.dll
. Hmm. -
eran otzap almost 11 years@Tower i don't know if i understood you right and if you still needed it, this is how you reference it via XAML , after adding the Reference to your project of course . xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
-
eran otzap over 10 yearsI'm searching under PresentationFramework.dll using reflector , i can't seem to locate any of the themes .dlls where are they physically located ?
-
New Bee over 10 yearsThank you for this, in VS2012 Windows.Themes was working then i updated to VS2013 (Worst mistake eva)
-
eran otzap about 10 years@Tower where can i physically find PresentationFramework.Aero.dll ?
-
eran otzap about 10 yearswell i wasn't able to physically locate it , but you can download it from here : dllme.com/dll/download/6959/PresentationFramework.Aero.dll
-
Edgar about 9 yearsI had the same problem and I confirm: Works fine after I added PresentationFramework.Aero.dll