Reputation: 14246
I am learning how to create a Class Library (Windows Store apps)
and used a UserControl
template to add a user control to it.
Then I added a Grid
tag to accompanying XAML. However, the tag is underlined with blue squiggles and when I hover over the tag there is
Grid is not supported in a Windows Presentation Foundation (WPF) project
tooltip shows up.
The library seems to build without errors. I've added the library to an application and use the control in its code. The application is also builds just fine. However, when I run the application I get XamlParseException
exception.
I am using Visual Studio 2012 RTM. Both the library and the application reference only two standard assemblies (.NET for Windows Store apps
and Windows
).
What I might done wrong and how should I fix the library?
Upvotes: 26
Views: 28501
Reputation: 965
I had a different reason for this issue after merging git branches inside of Visual Studio.
In all *.csproj
files a project reference to one of my projects was deleted. (A project with all my base classes.) As result I had 2500 build errors. Many of them like Grid / UserControl / etc. is not supported in a Windows Presentation Foundation (WPF) project
Solution:
Check the git diff for changed *.csproj
files. If there are only deleted project references, you can use the revert changes feature. If there are also wanted changes, undo the deletions manually.
Call clean solution and close Visual Studio!
Restart Visual Studio and build everything again.
This solved all the strange problems in my case. (Visual Studio 2022)
Note: It's important to close Visual Studio after cleaning. Without restart there were still many strange build errors. (about 500 instead of 2500)
Upvotes: 0
Reputation: 11
This problem is due to the low version of .NET that you have chosen in your project.
To solve the problem, select the Project from the up menu and then select your Project Properties and from the part of Target Framework select higher version of .NET Framework!
I hope your problem is solved. Yours sincerely
Upvotes: 0
Reputation: 1321
Much Like Felix D.s answer, I found from the .csproj file a reference was removed. Obviously replace the 3 with your needed framework, or use the project properties to set the version ( i think that adds this reference )
Evil Dog Pie was step 1 for me, as some other issues came up. There is always a heap of information in the output log
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
Upvotes: 0
Reputation: 603
I was able to solve my similar issue of..
UserControl is not supported in a Windows Presentation Foundation (WPF) project
.. by removing the PresentationFramework reference and re-adding it via nuget.
Upvotes: 2
Reputation: 890
This is xaml getting itself confused. I have the error on one project and not on another. Have a look at the top of the xaml before the grid error and see if there are any references to other controls. Try making a modification that will cause and error and rebuilding one of those controls. Then put it back the way it was to get a succesful build and see if this makes the grid error go away. (it did for me)
Upvotes: 0
Reputation: 13007
In my case I switched from Debug to Release, and then back, and the error was gone.
Upvotes: 39
Reputation: 5103
For me it helped to set the "Target framework" in application-properties to .NET 4.0
Upvotes: 2
Reputation: 2320
I've recently had the same error and found the following in the output window:
10>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFX.targets(268,9): error MC6000: Project file must include the .NET Framework assembly 'WindowsBase, PresentationCore, PresentationFramework' in the reference list.
The solution for me was to add the missing references to my project.
Upvotes: 6
Reputation: 788
Go to "Build > Configuration Manager..." and Make a new platform for x86 for all your projects.
It doesn't have to be the active one, you can leave that as Any CPU.
Hope it works as for mine...
Upvotes: 29
Reputation: 154
This appears to be a bit of a "catch-all" for a number of XAML resource errors. I've found two causes so far:
Forgetting to include the correct namespace for the "unsupported" class. Example in a basic ResourceDictionary, with no sys namespace defined:
<ResourceDictionary>
<sys:string>I'm not supported</sys:string>
</ResourceDictionary>
Upvotes: 1
Reputation: 23764
[Reposting comment as answer]
I was able to complete the steps with no issues, and it appears you were able to as well. Perhaps there was some other inadvertent modification/setting that was made?
Upvotes: 0