Я пытаюсь заставить DataGridComboBoxColumn связываться с перечислением, но все, что я получаю, это выпадающий список Empty.
Я пробовал несколько вещей с DisplayMemberPath и другими вещами, но безрезультатно.
Привязка к SkillName работает, но не SkillLevel
XAML:
<Window x:Class="EveCommon.Skills.EveSkillEditWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Common.Skills"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="Skills Window" Height="600" Width="600"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Window.Resources>
<ObjectDataProvider x:Key="SkillEnum" MethodName="GetValues" ObjectInstance="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:SkillLevels"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<DataGrid Grid.Row="1" ItemsSource="{Binding Skills}" AutoGenerateColumns="False" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" IsReadOnly="True" Binding="{Binding SkillName}"/>
<DataGridComboBoxColumn Header="Skill Level" DisplayMemberPath="SkillLevel"
SelectedValueBinding="{Binding Path=SkillLevel}"
ItemsSource="{Binding Source={StaticResource SkillEnum}}"/>
</DataGrid.Columns>
</DataGrid>
Enum:
public enum SkillLevels
{
Zero = 0,
I,
II,
III,
IV,
V
}
Класс навыка:
public class Skill : ImplementPropertyChanged
{
private string _skillName;
private SkillLevels _skillLevel;
public string SkillName
{
get => this._skillName;
set => this.SetField(ref this._skillName, value);
}
public SkillLevels SkillLevel
{
get => this._skillLevel;
set => this.SetField(ref this._skillLevel, value);
}
}
И сборник:
public ObservableCollection<Skill> Skills
{
get => this._skills;
set
{
this._skills = value;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Skills"));
}
}