2
votes

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
    }
}
2
Verify the namespace of the Converter. - Jawahar
I have included the Converter class also, the namespace is correct. Please take a look. - Sormita Chakraborty
Do I need to add the assembly MicroMVVM in AssemblyInfo.cs for it to be available in XAML? - Sormita Chakraborty

2 Answers

2
votes

Try to change this:

xmlns:micro="clr-namespace:MicroMVVM; assembly=MicroMVVM"

to:

xmlns:micro="clr-namespace:MicroMvvm;assembly=MicroMVVM"
0
votes

There is a space between semicolon and the word assembly in your prefix declaration. That will make syntax wrong. Try to remove that space and try again.