I have hit an odd situation in which an enum that is defined in a referenced assembly (dll that is a project in the same solution) is not found for use in my XAML. The same enum is found by C# code in my View Model.
When I copy the enum definition file into the project, the XAML references work, but the C# references, of course, complain about the duplicate definition. At this point I am at a loss as to how to resolve this issue. Any ideas? Known fixes?
Background:
- The referenced assembly contains the enum, which is being used to back a XAML radio group, as recommended here.
- I found this, but it does not apply to my situation. The enum in the referenced assembly stands on its own.
- The error is thrown on the first {x:static } binding parameter in the xaml (example below) and reads "Cannot find the type 'MyEnum'. Note that type names are case sensitive."
- Please excuse any minor mistakes in the below code, I typed it by hand since I can't disclose my company's production code.
EnumRadioGroupWindow.xaml
<Window x:Class="XamlWindow.EnumRadioGroupWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:XamlWindow"
xmlns:enum="clr-namespace:EnumLibrary">
<StackPanel>
<StackPanel.Resources>
<local:ComparisonToBoolConverter x:Key="ComparisonToBool"/>
</StackPanel.Resources>
<RadioButton Content="Item One" IsChecked="{Binding Path=InstanceOfMyEnum, Mode=OneWay, Converter={StaticResource ComparisonToBool}, ConverterParameter={x:Static enum:MyEnum.One}}"/>
<RadioButton Content="Item Two" IsChecked="{Binding Path=InstanceOfMyEnum, Mode=OneWay, Converter={StaticResource ComparisonToBool}, ConverterParameter={x:Static enum:MyEnum.Two}}"/>
<RadioButton Content="Item Three" IsChecked="{Binding Path=InstanceOfMyEnum, Mode=OneWay, Converter={StaticResource ComparisonToBool}, ConverterParameter={x:Static enum:MyEnum.Three}}"/>
</StackPanel>
</Window>
MyEnum.cs (in separate assembly that is referenced by the WPF project)
namespace EnumLibrary
{
public enum MyEnum
{
One,
Two,
Three
}
}