zoukankan      html  css  js  c++  java
  • 在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);

  • 相关阅读:
    8.图片切换
    6.节点的访问关系和操作
    4.京东狗
    3.关闭京东广告栏
    1.事件的拓展
    小飞鸟 小游戏
    网页特效(旋转木马轮播图)
    时间转换
    深入理解css3中的flex-grow、flex-shrink、flex-basis
    VUE 使用插件vue-clipboard2复制内容至剪切板(两种使用方法)
  • 原文地址:https://www.cnblogs.com/sjqq/p/8588259.html
Copyright © 2011-2022 走看看