Jens
Jens

Reputation: 3299

How to build library with WPF forms

Is it possible to build a Class Library dll which also includes WPF forms? When I try to build one I get following errors:

Error 1 Library project file cannot specify ApplicationDefinition element.
Error 2 The project file contains a property value that is not valid.

If I set my project as Windows Application it compiles & runs tho. Is there a way to get arround this? I'm using VS2010 & C# .NET 4.0 if that might be of any interest to you guys.

Thanks

Upvotes: 40

Views: 36371

Answers (6)

problems after copying XAML controls from WPF Application to class library

The first answer work for me. I changed App.xaml from ApplicationDefinition to Page and worked

Upvotes: 2

IbrarMumtaz
IbrarMumtaz

Reputation: 4403

Extending @2493490 answer.

Right click on the app.xaml file and exclude it from the project. Change the project output type to in project properties to Class Library. Click on the run icon, the solution will successfully build but will not run/execute any code. A error message will be displayed explaining as such.

Upvotes: 1

user2493490
user2493490

Reputation: 109

Remove the App.xaml and App.xaml.cs in your WPF Project. Then you will be able to run the project with an output type of Class Library.

Upvotes: 11

aditya potdar
aditya potdar

Reputation: 357

This is also occur when we copy paste an Image to ClassLibrary Project.

Change the Build Action Property of that image to resources

Upvotes: 8

Mikl X
Mikl X

Reputation: 1249

Change the build action of your UserControl from ApplicationDefinition to Page.

Upvotes: 30

decyclone
decyclone

Reputation: 30840

Choose WPF Custom Control Library or WPF User Control Library when creating/adding new project to your solution.

Upvotes: 45

Related Questions