在WPF中获取DataGridTemplateColumn模板定义的内容控件

xaml格式描述:


            
              
                    
                        
                            x:Name="expander" Header="{Binding Describe}">
                                
                            
                        

                    

                

            

        

 

现在要获取expander控件,代码如下:

int index = dataGrid.CurrentCell.Column.DisplayIndex;

DataGridTemplateColumn templeColumn = dataGrid.Columns[index] as DataGridTemplateColumn;

if(templeColumn == null) return;

object item = dataGrid.CurrentCell.Item;

FrameworkElement element = templeColumn.GetCellContent(item);
Expander expander= templeColumn.CellTemplate.FindName("expander", element);

转载于:https://www.cnblogs.com/eric_ibm/p/3772516.html

你可能感兴趣的:(在WPF中获取DataGridTemplateColumn模板定义的内容控件)