Problems after copying XAML controls from WPF Application to a class library

When you copy and paste files either within a project or to another project, Visual Studio has a nasty habit of not keeping the same BuildAction property. It often changes the build action to a seemingly random value, e.g. ApplicationDefinition, which causes that build error.

Check (in the Visual Studio properties window with the file selected in the Solution Explorer) that each of your .xaml files have a BuildAction property of Page and your code files have a BuildAction property of Compile.


You may also see this even though your build actions are set correctly. For example, if you start your project up as an Application, and then later switch it to be a Class Library. In which case you must also remember to delete App.xaml (and the corresponding App.cs).

Tags:

.Net

Wpf

Xaml