Ссылка на объект не указывает на экземпляр объекта xaml
Требуется вывести в datagrid enum в виде combobox, посмотрел здесь как это реализуется https://www.cyberforum.ru/wpf-silverlight/thread1798263.html, при создании combobox непосредственно в окне приложения всё работает, но при попытке записи combobox в datagrid при выборе элемента вылезает ошибка null reference exeption, в самой разметке так-же есть ошибка
Мой EnumItemSource
class EnumItemSource : Collection<string>, IValueConverter
{
Type type;
IDictionary<Object, Object> valueToNameMap;
IDictionary<Object, Object> nameToValueMap;
public Type Type
{
get { return this.type; }
set
{
if (!value.IsEnum)
throw new ArgumentException("Type is not an enum.", "value");
this.type = value;
Initialize();
}
}
public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
{
return this.valueToNameMap[value];
}
public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture)
{
return this.nameToValueMap[value];
}
void Initialize()
{
this.valueToNameMap = this.type
.GetFields(BindingFlags.Static | BindingFlags.Public)
.ToDictionary(fi => fi.GetValue(null), GetDescription);
this.nameToValueMap = this.valueToNameMap
.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
Clear();
foreach (String name in this.nameToValueMap.Keys)
Add(name);
}
static Object GetDescription(FieldInfo fieldInfo)
{
var descriptionAttribute =
(DescriptionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute));
return descriptionAttribute != null ? descriptionAttribute.Description : fieldInfo.Name;
}
}
xaml код ресурса
<UserControl.Resources>
<ResourceDictionary>
<enums:EnumItemSource x:Key="EnumItemSource" Type="{x:Type equipmentModel:TypeMatrix}"/>
</ResourceDictionary>
</UserControl.Resources>
![[]](https://i.stack.imgur.com/q0usQ.png)