Question

Please forgive the noob question but I'm going round in circles and need answers...

Anyway, I've been looking at this article WPF: How to bind RadioButtons to an enum? but I just can't get the convertor to be recognised within the XAML file.

<Window x:Class="Widget.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    Title="Widget" Height="366" Width="588" WindowStyle="SingleBorderWindow">
    <Window.Resources>
        <EnumBooleanConverter x:Key="enumBooleanConverter" />
    </Window.Resources>
...

I have a seperate file holding the EnumBooleanConverter class but the above reference gives me the following error:

Error 1 The tag 'EnumBooleanConverter' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.

I've tried adding references to the assembly and then appending the tag to the XAML but to no avail.

<Window x:Class="Widget.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:local="clr-namespace:Widget;assembly=Widget"
    Title="Widget" Height="366" Width="588" WindowStyle="SingleBorderWindow">
    <Window.Resources>
        <local:EnumBooleanConverter x:Key="enumBooleanConverter" />
    </Window.Resources>
...

Any help would be greatly appreciated.

Was it helpful?

Solution

After much head scratching (and a fair amount of shouting at the screen) I have identified the problem.

It turns out that identifying the namespace shouldn't have the assembly.

I was defining it like this

xmlns:local="clr-namespace:Widget;assembly=Widget"

... But it should have just been like this

xmlns:local="clr-namespace:Widget"

OTHER TIPS

Make sure EnumBooleanConverter is publicly accessible and it has a public empty constructor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow