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);

  • 相关阅读:
    [SDOI2011] 消防 (树的直径,尺取法)
    [HNOI2006]公路修建问题 (二分答案,并查集)
    P1875 佳佳的魔法药水 (最短路,DP)
    [SCOI2016] 背单词 (Trie 树,贪心)
    [USACO08DEC] 秘密消息Secret Message (Trie树)
    [HDU4745] Two Rabbits (区间DP)
    [HDU4362] Palindrome subsequence (区间DP)
    评价手心输入法
    软件工程个人作业12
    第12周进度条
  • 原文地址:https://www.cnblogs.com/eric_ibm/p/3772516.html
Copyright © 2011-2022 走看看