Не работает привязка DataGridComboBoxColumn ItemSource к списку

215
21 мая 2018, 16:50

К Datagrid подключается коллекция с одним элементом. Отображается только ячейка с датой. Остальный ячейки, которые представлены Combobox пустые.

Код XAML:

<DataGrid IsReadOnly="False" Style="{DynamicResource TableForAdmin}" ItemsSource="{Binding AddAttestation}" Visibility="{Binding IsChecked,ElementName=AddAttestationCheck,Converter={StaticResource b2v}}">
<DataGrid.Columns>
    <DataGridComboBoxColumn Header="Дисциплина" Width="1*" ItemsSource="{Binding Disciplines}" SelectedValueBinding="{Binding SelectedDiscipline}"  />
    <DataGridComboBoxColumn Header="Преподаватель" Width="1*" ItemsSource="{Binding Teachers, Converter={StaticResource tc} }" SelectedValueBinding="{Binding SelectedTeacher}"/>
    <DataGridComboBoxColumn Header="Группа" Width="1*" ItemsSource="{Binding Groups }" SelectedValueBinding="{Binding SelectedGroup}"  />
    <DataGridComboBoxColumn Header="Тип" Width="1*" ItemsSource="{Binding Type}" SelectedValueBinding="{Binding SelectedType}"  />
    <DataGridTextColumn Width="1*"  Header="Дата" Binding="{Binding Path=Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ></DataGridTextColumn>
    <DataGridTemplateColumn Header="Добавить" Width="0.7*">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Button Style="{DynamicResource ManipulateButton}" CommandParameter="{Binding}" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.Add}" Content="Добавить"></Button>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
</DataGrid.Columns>

Коллекция во ViewModel:

public ObservableCollection<FullAttestation> AddAttestation { get; set; } = new ObservableCollection<FullAttestation> { new FullAttestation {
        Disciplines = new ObservableCollection<int>( context.discipline.Select(x=>x.DisciplineId).ToList()),
        Teachers= new ObservableCollection<int>( context.teacher.Select(x=>x.TeacherId).ToList()), Groups = new ObservableCollection<int>( context.group.Select(x=>x.CodeOfGroup).ToList()),
        Date = DateTime.Now 
    } };

Класс для таблицы:

public class FullAttestation : NotifyBase
{
    private int attestationId;
    private string selectedGroup;
    private string selectedDiscipline;
    private string selectedTeacher;
    private ObservableCollection<int> teachers = new ObservableCollection<int>();
    private ObservableCollection<int> discipline = new ObservableCollection<int>();
    private ObservableCollection<int> groups = new ObservableCollection<int>();
    private ObservableCollection<int> type = new ObservableCollection<int> { 1,2};
    private DateTime date;
    private int selectedType = 1;
    public int SelectedTyoe { get { return selectedType; } set { Set(ref selectedType, value); } }
    public string SelectedGroup { get { return selectedGroup; } set { Set(ref selectedGroup, value); } }
    public string SelectedDiscipline { get { return selectedDiscipline; } set { Set(ref selectedDiscipline, value); } }
    public string SeletedTeacher { get { return selectedTeacher; } set { Set(ref selectedTeacher, value); } }
    public ObservableCollection<int> Disciplines { get { return discipline; } set { Set(ref discipline, value); } }
    public ObservableCollection<int> Groups { get { return groups; } set { Set(ref groups, value); } }
    public ObservableCollection<int> Teachers { get { return teachers; } set { Set(ref teachers, value); } }
    public ObservableCollection<int> Type { get { return type; } set { Set(ref type, value); } }

    public int AttestationId { get { return attestationId; } set { Set(ref attestationId, value); } }
    public DateTime Date { get { return date; } set { Set(ref date, value); } }
}

Вывод

READ ALSO
Программно создать RadioButton на TabControl c# [требует правки]

Программно создать RadioButton на TabControl c# [требует правки]

Как создать RadioButton на определенной вкладке TabPage, с определенными параметрами и события checked

166
Ошибка при загрузке страницы входа на сайте

Ошибка при загрузке страницы входа на сайте

Пытаемся получить корректный ответ от веб-сервера:

219
Вывод каталогов и файлов в один DataGrid

Вывод каталогов и файлов в один DataGrid

Суть такова, есть DataGrid и 2 списка с типом FileInfo и DirectoryInfo

196
Найти конечные координаты линии Line

Найти конечные координаты линии Line

Подскажите как найти конечные координаты линии после поворота

156