WPF中如何获取<DataTemplate>中的控件??求教!!
<ListView Name="listView" >
<ListView.View >
<GridView x:Name="gridView" >
<GridViewColumn Header="">
<GridViewColumn.CellTemplate>
<DataTemplate x:Name="gvColumnTemplate">
<Button name="btn"/>...后面省略
请问如何能获取到该Button按钮???谢谢!
后来自己解决的,现在来结帖都已经忘了怎么解决的...
请问你要取这个button干撒呢?
void DoMethod()
{
if (listView.ItemsSource != null)
{
foreach (var item in listView.ItemsSource)
{
Button btn = GetButton(item);
}
}
}
private Button GetButton(object item)
{
return listView.Columns[0].GetCellContent(item).FindName("btn") as Button;
}