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"
Related
So I have 2 projects in my solution. A class library and a WPF project.
The class library "TemplateGeneratorLibrary" contains a file "Enums.cs" where I define my enums.
namespace TemplateGeneratorLibrary.Utilities
{
public enum Genders
{
m,
f
}
}
I've added the following reference to my view file in my UI project. I double checked that the assembly name of the class library is indeed "TemplateGeneratorLibrary" and is not different from the project name.
<UserControl x:Class="TemplateGeneratorUI.Views.MedicalExaminationView"
xmlns:utilities="clr-namespace:TemplateGeneratorLibrary.Utilities;assembly=TemplateGeneratorLibary">
Now I'm trying to bind a radio button group to a property in my viewmodel using the enum from the class library.
<RadioButton x:Name="PatientGenderMRadio"
IsChecked="{Binding Path=Gender, Converter={StaticResource enumConverter}, ConverterParameter={x:Static utilities:Genders.m}}"
I'm getting the error "Cannot find the type 'Genders'. Note that type names are case sensitive."
When I put the enum file in the same project as the view everything works fine. How can I get it to work using the enum from my class library though?
When I put the enum file in the same project as the view everything works fine.
One can actually bring in specific files from another project without having to bring in the reference to the project or include the dll.
The trick is to include the file needed as a link into the project. Here is how
In the main project right click and select Add then Existing Item... or shift alt A.
Browse to the location of the file(s) found in the other project and select the file(s).
Once the file(s) have been selected, then on the Add button uses the select in the drop down arrow.
Select Add as link to add the common files(s) as a link into the project.
That will give access to the file as if the file was actually within the project, but the file physically resides elsewhere.
This was used extensively in Silverlight where one had to cross CLR boundaries, but things like models and enums could be used in both projects without having to pull in another CLRs dll just for textual type copies.
If you are using .NET Standard, the class library must also be built on the .NET Standard.
And if the .NET Framework or .NET Core class library must comply with it.
Class library namespace does not exist in WPF app despite project reference
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.
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
I have been implementing this solution explained here to make an outlinedTextbox.
I have created a test project and added directly in the main namespace and it works.
Now I want to add it to a library (HelperLib) and want to use it in whatever program of mine I want. For example here the program is called pcdLoggerS2.
but when I add it to my xaml it says that
so it's a matter of namespaces.
Therefore I have add this
xmlns:local="clr-HelperLib"
in my definition of my Base:WindowViewBase but nothing has changed but it's really in that namespace!
--ADD FOR DAVID---
You need to make sure that you've added the HelperLib project as a reference to your test project.
Open PcdLogger and right click on References, and add that project as a reference. Until you do this, the XAML in your test project will not be able to find the correct assembly.
Additionally, when you reference a namespace, from another assembly, you need to add that information to the namespace declaration in your XAML.
(See: https://msdn.microsoft.com/en-us/library/bb514546%28v=vs.90%29.aspx)
As an example:
(I would suggest leaving local for your local namespaces)
xmlns:helper="clr-namespace:HelperLib;assembly=HelperLib"
EDIT:
Additionally, Visual Studio's intellisense is fond of telling you that the namespace, or class, does not exist until you have built the project. You may have to rebuild and/or close/reopen the xaml file for intellisense to cooperate again.
check Namespace of you class.
HelperLib its name of a class, but not namespace.
Try to write this:
xmlns:local="clr-namespace:HelperLib"
So, everything is in the title, I just want to add a UserControl in my WPF Window. It looks like easy but the UserControl is in another project (Dll project) in the same solution. And I just can't reference it.
So, my best try is something like that:
<Window xmlns:local="clr-namespace:MyWindowProject" x:Name="window"
xmlns:other="clr-namespace:MyDllProject"
x:Class="MyWindowProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<other:MyUserControl />
</Window>
I know I am near to find how to make it because I've got just one error and the autocompletion is working on MyUserControl. But, I've got this weird error: "The name 'MyUserControl' does not exist in the namespace "clr-namespace:MyDllProject".
I'm sure that I'm doing something wrong, but I really don't know what...
xmlns:other="clr-namespace:MyDllProject"
The above import statement show's that you are pointing the namespace of your local project. if you want to add a refrance of the other project (The Dll Project) then you must add the namespace as like
xmlns:other="clr-namespace:MyDllProjectNamespace;assembly=MyDllProject"
This will point the namespace which exists in Other assembly.
See this Article to understand the namespaceing in Xaml
Condition Make sure the using control is accessible from the other assemblies.
Add your user control to the controls tool box, and drag'n drop from there to your form. Visual Studio will take care of namespaces and things like that.
Add the dll reference to your project.
Post that add the namespace of this usercontrol to your xaml
say xmlns:local="... dll path;assembly=...."
Now the user control will be accessible in your xaml