首页 新闻 搜索 专区 学院

WPF Tookit DataGrid 模板列的CheckBox获取问题

0
悬赏园豆:60 [已关闭问题] 关闭于 2012-03-27 14:36
View XAML
 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>
View Code
 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 . 请园长们帮忙指点迷津,谢谢!

mayixue的主页 mayixue | 初学一级 | 园豆:29
提问于:2012-03-20 11:56
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册