简体   繁体   中英

Grid is not supported in a Windows Presentation Foundation (WPF) project

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?

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

就我而言,我从 Debug 切换到 Release,然后返回,错误消失了。

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.

对我来说,它有助于将应用程序属性中的“目标框架”设置为 .NET 4.0

This appears to be a bit of a "catch-all" for a number of XAML resource errors. I've found two causes so far:

  1. Declaring a Resource outside of the appropriate context- eg directly in a UserControl tags, not UserControl.Resources.
  2. 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>

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.

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)

Much Like Felix Ds 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>

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM