开发者

Moved silverlight file (xaml) to a different project, and now code behind doesn't recognize the controls

I moved a silverlight file (xaml) to a different project, and now code behind for the file doesn't recognize the controls.

xaml.cs file does not see controls in xaml file

I've updated the namespace, but that doesn't help.

I've updated the class names to be the same, still doesn't help.

Intelisence doesn't pick up the controls.

Any ideas? I tried deleting the cs file as well, but there's no option to "auto re-c开发者_JAVA百科reate cs file"

Thanks!


In VS2010 check the properties of the xaml file. Its Build Action should be "Page" and its Custom Tool should be "MSBuild:Compile". Also check that the x:Class element in the xaml contains the correct fully qualified name that matches the namespace and class name in the code-behind .xaml.cs file.


A XAML file generates a partial class, essentially. A code behind file is another partial class with the same name. A class cannot be declared across two different projects, which is what you are doing.


I have the same problem. I found the Build Action was changed to Application definition. After changing it to Page, and deleting the obj folder , everything is OK. Thanks .


Have you checked the namespace / class name of the XAML file and code-behind? I have often forgotten to change the namespace in the code-behind file when moving a XAMl file to another project.


I have the similar problem in a WPF project. One thing I noticed is that if you put something like following in section:

<x:Array Type="sys:String" x:Key="RuleBinaryOperatorList" xmlns:sys="clr-namespace:System;assembly=mscorlib"> <sys:String>AND</sys:String> <sys:String>OR</sys:String> </x:Array>

It makes the corresponding XAML file not compileable and complaining about InitializeComponent not recognized. The solution is to put such resources into section inside App.xaml instead.

Hope it helps someone out there!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜