Copying Silverlight XAML project files and “Not available in this context” error in Visual Studio 2010

If you copy XAML project files (usually pages) and their attached code behind from one Silverlight project to another one using Solution Explorer in Visual Studio 2010, you may receive an error at build time: named elements may not be recognized anymore in the copied code behind of the destination project, although their names are still correctly set using x:Name within the copied XAML files (the error message would indicate that “ElementName is not available in this context.”).

The problem is that sometimes XAML files copied to Silverlight projects do not get their Build Action property copied from the source project (the default ApplicationDefinition value is set instead), even that it might be presented as correct in the Properties window.

To resolve the issue select each of the destination Silverlight XAML files in Solution Explorer, and update their Build Action property in the Properties window of Visual Studio to the correct value (usually Page). If it seems already set to the correct value, change it manually to ApplicationDefinition, then back to the correct value, and clean/rebuild the solution.

If the issue reappears, delete Obj folder from the Visual Studio project folder in Windows Explorer.


About Sorin Dolha

My passion is software development, but I also like physics.
This entry was posted in Computers and Internet and tagged , , , , , . Bookmark the permalink.

Add a reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s