I have an EnumToBool Converter class in a dll file MicroMVVM. I want to import and create a resource of this class in XAML of my WPF application. Following is how my declaration in XAML looks like:
<Window x:Class="WpfMVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfMVVM"
xmlns:micro="clr-namespace:MicroMVVM;assembly=MicroMVVM"
Title="MainWindow" Height="350" Width="525" ContentRendered="Window_ContentRendered">
<Window.DataContext>
<!-- Declaratively create an instance of our SongViewModel -->
<local:SabrixQAViewModel />
</Window.DataContext>
<Window.Resources>
<micro:EnumToBoolExtension x:Key="EnumToBool" />
</Window.Resources>
I am getting error in "clr-namespace". The error is "Undefined CLR namespace.The 'clr-namespace' URI refers to a namespace 'MicroMVVM'that is not included in the assembly.
I have added a reference of MicroMVVM.dll in my solution and i am using other classes of the dll in the ViewModel. However, I am getting error while trying to use it in XAML. Please help.
Following is how the Converter class looks inside MicroMVVM:
namespace MicroMvvm
{
public enum ValidationMode
{
GSS,
Digital
}
[ValueConversion(typeof(bool), typeof(Enum))] //This is converting boolean value to a value in Enum
public class EnumToBoolExtension : MarkupExtension, IValueConverter
{
#region IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return parameter.Equals(value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((bool)value) == true ? parameter : DependencyProperty.UnsetValue;
}
#endregion
#region MarkupExtension
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
#endregion
}
}