1 <toolkit:DataGrid Name="grid" AutoGenerateColumns="False" ItemsSource="{Binding Documents, NotifyOnTargetUpdated=True}" Grid.Row="0" IsReadOnly="True" SelectionMode="Extended" SelectionUnit="FullRow">
2 <toolkit:DataGrid.Columns>
3 <toolkit:DataGridTemplateColumn Header="选择" Width="50">
4 <toolkit:DataGridTemplateColumn.CellTemplate>
5 <DataTemplate>
6 <CheckBox x:Name="ck" Tag="{Binding Id}" HorizontalAlignment="Center"></CheckBox>
7 </DataTemplate>
8 </toolkit:DataGridTemplateColumn.CellTemplate>
9 </toolkit:DataGridTemplateColumn>
10 <toolkit:DataGridTextColumn Header="ID" Binding="{Binding Id}" Visibility="Hidden"/>
11 <toolkit:DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
12 <toolkit:DataGridTextColumn Header="Age" Binding="{Binding Age}"/>
13 <toolkit:DataGridTextColumn Header="Sex" Binding="{Binding Sex}"/>
14 </toolkit:DataGrid.Columns>
15 </toolkit:DataGrid>
16
17
18 <CheckBox Name="cbCheckAll" Grid.Row="2" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="cbCheckAll_Click">全选</CheckBox>
1 private void cbCheckAll_Click(object sender, RoutedEventArgs e)
2 {
3 if (grid.ItemsSource != null)
4 {
5 bool _flag = this.cbCheckAll.IsChecked.Value ? false : true;
6
7 foreach (object ovj in grid.ItemsSource)
8 {
9 if (null != grid.Columns[0] && null != grid.Columns[0].GetCellContent(ovj))
10 {
11 CheckBox cb = grid.Columns[0].GetCellContent(ovj).FindName("ck") as CheckBox;
12 if (null != cb)
13 {
14 cb.IsChecked = _flag;
15 }
16 }
17 }
18 }
19 }
上面是问题相关代码,WPFTookit DataGrid不能找到模板列的CheckBox,cb一直为null . 请园长们帮忙指点迷津,谢谢!