views:

312

answers:

3

When I move .xaml and .xaml.vb files to a new Silverlight project, the generated .g files no longer include members for the x:Name attributes defined in the xaml file. This means the code-behind files can't refer to those members and cannot build.

+1  A: 

I think I have answered my own question. If you copy and paste a usercontrol from one project to another using the Visual Studio Solution Explorer, it puts that usercontrol into the vbproj file (not sure about csproj) as an ApplicationDefinition instead of as a Page. For example, changing the xml in the vbproj to look like this for each usercontrol:

<Page Include="calculator.xaml">
  <Generator>MSBuild:MarkupCompilePass1</Generator>
  <SubType>Page</SubType>
</Page>

...fixes the problem.

This is one bit of tool voodoo that makes me uneasy, but at least the files are transparent so you can figure them out and modify them.

This seems like a bug in Visual Studio.

Pete
+1  A: 

In Visual Studio, select the .xaml file and in the properties, set the file's Build Action to Page. You shouldn't need to modify the project file by hand.

Michael S. Scherotter
A: 

Even if this will not do, then try this:

  1. Remove the file which you manually added from explorer manually. You would rather want to use VS to add it.
  2. Right click on the project and click on Add->Existing Item.
  3. VS will do the rest of the job of syncing the codebehind and XAML.

Bharath

Bharath chandra