Windows Forms Designer can't find DLL - c#

I have a Problem with using Usercontrols from another Library.
I have a Project Solution in the Project Solution are two Projects (the Main Program and a Library) in the Library are my custom Usercontrols and some Objects which will be used from the Usercontrols. For example a custom List View which shows some informations from the Object that is given.
My Problems are:
that the Designer cant found the Library which I added over the Toolbox (choose elements...) and
that when I try to choose an Object instance (which should be shown) the designer says that it cant be found although the Object class is public.
I hope you can help me.

Related

c# winforms - calling form from another dll (c#) missing show() and showdialog()

I have some project (app) in c# winforms(.net framework 3.5). Project is builded from few smaller projects. In all this smaller project there are some forms. Right now I need create seperate project (app) and I want use one of this smaller project by his dll.
I adding dll to project by reference, I see form that I need so I create object. I see some my custom proporties but I don's see basic methods like Show() or ShowDialog(). Honestly I don't know were is problem. I tired some someone else's dll from different source and different framework's and It's worked. So I'know there is problem in my 'main' app but I don't remember any proporties which disable visibiltes of this methods. What can I do to get all the methods back?
Project which I try using dll are library type. When I'm using it in that main app I see all methods.
Maybe I show screen:

How to use a WPF User control in a different namespace [duplicate]

I have created a class library(CustomMapControl) in the solution and inside this class library I create a UserControl(MapItemsControl).
Now, I added a reference of this class library to both projects (Portogruaro & Trieste).
Here is my solution structure.
Portogruaro is the main project and has all files, Trieste has almost all the files which Portogruaro have added as a reference.
So, the problem is when I tried to use the CustomMapControl and drag and drop it in xaml from toolbox it doenst build and give this error
the name "MapsItemControl" doesnt exist in namespace "clr-namespace:CustomMapControl"
And sometimes it shows this error
Element is already a child of another element
Here is the xaml namespace
xmlns:cc="clr-namespace:CustomMapControl"
and this is the user control in xaml
<cc:MapItemsControl /> <cc:MapItemsControl />
The error changes when I open xaml file from different projects.
The xaml file in which I want to have this UserControl is also shared between the two projects.
I am quite sure that this is a referencing issue.
I have no idea how to reference the CustomMapControl so it will work for both the projects.
You probably have a problem with how your namespace is added in your wpf project. Instead of:
xmlns:cc="clr-namespace:CustomMapControl"
try this:
xmlns:cc="clr-namespace:CustomMapControl;assembly=CustomMapControl"

Form design from dll project other than from winforms project

So when I create and do what ever I like to do with a winforms project on my Win10 PC, all the forms in that project have that kind of Metro Style UI design.
However if I create a dll project on the same PC, and reference to what I think is the same System.Windows.Forms dll as the winforms projects do, the forms I can create from the dll look a little bit as if I was on Win7 and had enabled the use XpVisualStyles option.
i.e.: As an basic example: all buttons on the form are set to a 3d border style by default and trying to get them to be flat is not that easy (if they should look good atleast)
Question is: Why do the forms created from the dll look differend than the ones created from a winforms application, althought they both reference the same dll (System.Windows.Forms I even checked hash and version)?
2nd Part how can I get the forms created from the dll to look like the ones from an winforms project?
Additional Information: The dll forms have been created by referencing the dll from 1 a console project and 2 an other winforms project. Both looked like Xp.
So thanks to the nice comment by #Reza Aghaei this question is solved.
1st Solution
Make sure that in the Application that opens the form the Appliction.EnableVisualStyles(); is called, this requires a reference to System.Windows.Forms if there is none.
The shown form will then look just like it shows you in the designer that it will.
2nd Solution
Call the Appliction.EnableVisualStyles(); inside the dll that owns the form.
This be done by
Calling in the constructor of each form
Or via some static function in the dll that takes care of all initialization
additionally there could be a conditional inside the form constructor that calls some function of the same dll that checks if styles are enabled and if not does so.
I would based on my knowledge commend to use a static initialization function.

Building wpf application as type of wpf class libarary

My need is to develop an addin for an application
but WPF application is not allowing to build it in type of WPF Class Libarary
Refering to this question i found that without XAML pages only we can build WPF application in Class Library Type. It it true? Or am I missing something?
I need to add a WPF window to my addin, but they are referring to remove all the windows and add usercontrol? Whats the workaround for it? Or am i doing anything wrong?
What i did now is I just deleted my application.xaml window from my solution and changed the target type to WPF class Libarary and builded the solution and it builded successfully. Is it correct way..? or any other ways there..? Am really new to this WPF !
There two additional templates to build WPF dll's such as WpfCustomControlLibrary and WpfControlLibrary. You will then be able to add a Window (and other WPF-specific elements). And it can certainly contain general-purpose classes. And it will be built into an assembly no different from that from general class library project.
How to: Create a WPF UserControl Library Project
How to add a WPF control library template to Visual C# Express 2008
If you want just create class libary, please, just select Class Library
How to: Create Class Library.
Also, you can add Window to general class library project. Visual Studio just does not expose Window from add new items dialog. A workaround is to add a User Control Item, and then change it to derive from Window.
Yes, you can go on creating a Class Library, adding a XAML view there. In your exe project you will include a reference to that lib and its public XAML windows or user controls should be available under the library's namespace, like any C# class.
Edit
A simple example from GitHub: as you can see, the library project is compiled with a reference to the System.Xaml assembly.
Edit 2
To build an already existing Windows Application project into a Class Library one, besides changing the Output type you have to delete only the App.xaml

C# WPF Library creating

I have a WPF project. I want to use this project in other new projects using a .DLL file, Like MessageBox form in C#, when we use MessageBox.Show to create a form.
Library project file cannot specify ApplicationDefinition element.
When i change the output of the project to "Class Library", the "InitializeComponent();" method makes an error, so does many other methods in the constructor of my window, saying
The name 'InitializeComponent' does not exist in the current context
How do i solve this? and how do i use my library once created?
You can't simply port it to a Class Library. You can hack at the app.xaml and so forth, but it would be best if you create a new "WPF User Control Library" or "WPF Custom Control Library". Migrate over your existing code to it. Make sure to expose Public classes and methods that you wish to call from outside of the library.
You can create a Solution to contain your new library as well as a test WPF Application. That way you can add a reference in the application pointing to your library project. Testing would be easier that way.
As far as how to use the library -- you'll need to do some research on that. There are a number of ways to go about it depending on your needs.
OK, the problem is that you project is an app, not a library. Just changing it to library in settings wont help.
The best this to do is to create a new project of type 'user control library', and then copy all of your xaml and classes over to the new project
Deleting App.xaml from my project worked.

Categories