分享

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

 Jcstone 2013-07-03

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

(转载)

xaml格式描述:

<DataGrid Name="dataGrid" Grid.Row="1" ItemsSource="{Binding}"  >
            <DataGrid.Columns>
              <DataGridTemplateColumn Header="描述">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Expander x:Name="expander" Header="{Binding Describe}">
                                <TextBlock Text="{Binding Path=Exception}" TextWrapping="Wrap"  MinHeight="30"  MinWidth="250" />
                            </Expander>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

 

现在要获取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);

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多