Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a Class Library project and need to access few controls from the namespace using System.Windows.Controls but getting error this namespace name controls doesn't exist in System.Windows.

What I have tried:

Tried to add as a reference by right click on the project but couldn't find this reference. Need some help in adding this reference.
Posted
Updated 27-Feb-23 2:53am

It depends on which class library you chose. There is the Base Class Library, then there is the WinForms class Library or the WinForms Control Libary. There are the same options for Wpf.

If you are doing Controls in a Library, then you need to select the correct one.

However, you can create a new library, open the project file, and copy the references into your own project file. Once saved, open the project in visual studio and try again.
 
Share this answer
 
Comments
Rocky_Bas 27-Feb-23 7:03am    
Its a Class Library Project
Ralf Meier 27-Feb-23 7:27am    
If you really want to get Help or Assistance YOU should give (like Andre Oosthuizen has mentioned as a Comment) MUCH MORE INFO ...
Your Comment here isn't a useful Info (for me) ...
Graeme_Grant 27-Feb-23 7:31am    
You can't drive a car without a motor or wheels...

If it is a pure class library project, then there are various Microsoft Libraries missing. You need to add those missing references.
If it's a separate assembly - and each project creates a single assembly - then you probably need to add a Reference to it in each project that you want to use it. This shoudl help: Add references in the Reference Manager - Visual Studio (Windows) | Microsoft Learn[^]
 
Share this answer
 
What are you doing in the library that needs access to UI controls? This sounds a bit suspicious in that unless you're writing your own control library, or an extension to controls, you never need to do this. Adding references to UI libraries and interacting with UI controls directly ties your library to only being used by that kind of application. So, for example, if your library does some data processing and interaction with WPF controls, you can only ever use the library in a WPF app. You cannot use it in a web app of any kind if the need arises, forcing you to rewrite the library.

Having said all that, you seem to be wanting to add references to WindowsBase.dll, PresentationFramework.dll, and PresentationCore.dll. After you right-click the References item in Solution Explorer, pick Add Reference. In the dialog that shows up, under the Assemblies item in the top-left corner of the window, you'll find Framework. Click that and you can put a checkmark next to the .DLL's I listed. When done, click OK and the references will be set.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900