标签:
<DataGrid Name="DG">
<DataGrid.Columns>
<DataGridTemplateColumn Width="70">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<CheckBox Name="cbbSelALL" Content="全选" Click="cbbSelALL_Click"/>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding SelFlag}" Name="cbsel"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
public T GetVisualChild<T>(DependencyObject parent, Func<T, bool> predicate) where T : Visual
{
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
DependencyObject v = (DependencyObject)VisualTreeHelper.GetChild(parent, i);
T child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v, predicate);
if (child != null)
{
return child;
}
}
else
{
if (predicate(child))
{
return child;
}
}
}
return null;
}
CheckBox chb = GetVisualChild<CheckBox>(DG, v => v.Name == "cbbSelALL");
if (null != chb)
{
chb.IsChecked = false;
}
WPF DataGrid DataGridTemplateColumn 控制模板中控件
标签:
原文地址:http://www.cnblogs.com/wby0405/p/5551929.html