Я получаю «Операция недействительна при использовании ItemsSource. Доступ и изменение элементов с помощью ItemControl.ItemsSource вместо», и я не уверен, почему.DataGrid, вложенный в проблему DataGrid
Я пытаюсь вставить datagrid внутри datagrid. Если я просто использую текстовый блок, у него нет проблем, но как только я назначу значение и нажму на один из элементов родительского элемента данных, я получу вышеуказанную ошибку.
Вот моя XAML:
<DataGrid Grid.Row="1" Name="dgSREducation" Background="White" AutoGenerateColumns="False" CanUserAddRows="False" HorizontalAlignment="Left">
<DataGrid.Columns>
<DataGridTextColumn Header="Description" Binding="{Binding Description}"/>
<DataGridTextColumn Header="Link" Binding="{Binding Link}"/>
<DataGridTextColumn Header="Type" IsReadOnly="True" Binding="{Binding Type}"/>
<DataGridCheckBoxColumn Header="Active" Binding="{Binding Active}"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel>
<DataGrid ItemsSource="{Binding Conditions}" AutoGenerateColumns="False" CanUserAddRows="False">
<DataGridTextColumn Header="Notification Type" IsReadOnly="True" Binding="{Binding Notification}"/>
<DataGridTextColumn Header="Value" Binding="{Binding Value}"/>
<DataGridTextColumn Header="Compare Type" IsReadOnly="True" Binding="{Binding Compare}"/>
<DataGridCheckBoxColumn Header="Active" Binding="{Binding Active}"/>
</DataGrid>
<TextBlock Text="{Binding Words}"></TextBlock>
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
<DataGrid.Resources>
<Style TargetType="DataGridRow">
<EventSetter Event="MouseLeftButtonDown" Handler="Education_Click"/>
</Style>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{x:Static SystemColors.HighlightColor}"></SolidColorBrush>
</DataGrid.Resources>
</DataGrid>
Мой класс для всех это:
class SREducationData
{
public NamedIDData Type { get; set; }
public bool Active { get; set; }
public string Link { get; set; }
public string Description { get; set; }
public long ID { get; set; }
public ObservableCollection<ConditionData> Conditions { get; set; }
public string Words { get; set; }
}
и:
class ConditionData
{
public long ID { get; set; }
public NamedIDData Notification { get; set; }
public bool Active { get; set; }
public string Value { get; set; }
public NamedIDData Compare { get; set; }
}
Когда моя программа первоначально нагрузки я устанавливаю ItemSource в коде, сделав dgSREducation.ItemsSource = display;
, где отображается ObservableCollection<SREducationData> display;
Как только я нажимаю на один из элементов dgSREducation, я получаю сообщение об ошибке, и под этим элементом появляется пустой datagrid. Любые мысли о том, что происходит?
Awesome! Спасибо! – Will