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
Add
then Existing Item...
or shift alt A.Add
button uses the select in the drop down arrow.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.