Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type 'Window' does not support direct content

I have a WPF solution built with VS 2015 composed of several projects. Suddenly I started receiving a warning in design mode stating the following:

The type 'Window' does not support direct content.

I understand how some controls do not support direct content, but System.Windows.Window should. I get the same warning with UserControl, and as far as I know, any other control that typically supports direct content.

Everything compiles and runs fine, but having the blue underlines through all of my XAML is bothersome. Has anyone else come across this?

Below is a screenshot:

enter image description here

like image 903
mrtedweb Avatar asked Nov 19 '15 13:11

mrtedweb


4 Answers

Make sure you reference System.Xaml. Clean and rebuild the project. Works on VS 2015 Update 1.

like image 177
Mark Richman Avatar answered Oct 13 '22 21:10

Mark Richman


At least in a WPF IronPython project, adding the System.Xaml reference to the project solved the problem for me:

enter image description here

An important thing to note here is that adding seemingly any reference will make the problem go away temporarily -- until Visual Studio is restarted. System.Xaml, on the other hand, appears to keep the problem at bay. I even tried removing the reference, whereafter the problem returned upon restarting Visual Studio.

like image 35
Michael Avatar answered Oct 13 '22 22:10

Michael


For me this error was happening because I added a WPF Window to a class library project.

For some reason (unknown by me), Visual Studio doesn't give us the option to select the WPF Window template from the "Add New Item..." dialog box if the project was not created as a WPF Application. Instead, it only offers the option to add a WPF User Control. Because of that, I selected the User Control template for the new item, and then edited the source code to make the XAML to become a Window object rather than a User Control.

<!-- The new item was created as an UserControl, but what I needed was a Window object. -->
<UserControl>
   ...
</UserControl>

<!-- Changed it to Window and made other necessary adjustments. -->
<Window>
   ...
</Window>

The problem was actually in the code-behind. Since it was created as an User Control, the window partial class was inheriting from UserControl, like the following:

public partial class MyWindow : UserControl
{
    public MyWindow ()
    {
        InitializeComponent();
    }
}

To fix it I just had to remove the inheritance, making my window class inherith from nothing, like this:

public partial class MyWindow
{
    public MyWindow ()
    {
        InitializeComponent();
    }
}

After removing the inheritance, Visual Studio didn't show the error "The type 'Window' does not support direct content." anymore.

like image 6
Ulysses Alves Avatar answered Oct 13 '22 22:10

Ulysses Alves


on behalf of @mark Richman I edited the Itemtemplate to automatically Reference "System.Xaml". Just in case some is interested:

enter image description here

can be found in: "[VS InstallDir]\Common7\IDE\ItemTemplates\VisualBasic\WPF\[InputLocale]\WPFWindow"

BR, Daniel

like image 2
dba Avatar answered Oct 13 '22 23:10

dba