我在使用DataGridCheckBoxColumn时遇到一些问题。对于某些单元格,当我选中一个复选框时,会同时检查多个复选框。我应该如何防止这种情况?这是我的XAML。
<DataGrid IsReadOnly="True" Margin="10,0,10,8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="2" Name="newsStories" AutoGenerateColumns="False" RowHeaderWidth="0">
<DataGrid.Columns>
<DataGridTextColumn Width="8*" Header="Headline" Binding="{Binding Path=heading}">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.Padding" Value="5" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridCheckBoxColumn Header="Select" Width="2*" Binding="{Binding Path=isIncluded, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}">
<DataGridCheckBoxColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGridCheckBoxColumn.HeaderStyle>
<DataGridCheckBoxColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.HorizontalAlignment" Value="Center" />
<Setter Property="TextBlock.VerticalAlignment" Value="Center" />
</Style>
</DataGridCheckBoxColumn.ElementStyle>
<DataGridCheckBoxColumn.CellStyle>
<Style>
<EventSetter Event="CheckBox.Checked" Handler="handleChecked" />
<EventSetter Event="CheckBox.Unchecked" Handler="handleChecked" />
</Style>
</DataGridCheckBoxColumn.CellStyle>
</DataGridCheckBoxColumn>
</DataGrid.Columns>
</DataGrid>
我没有任何代码隐藏在这里显示。问题出在这里,即使我没有任何代码隐藏。
谢谢。