wpf中的父子网格问题 [英] Parent-Child Grid Issue in wpf

查看:79
本文介绍了wpf中的父子网格问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在设计一个wpf应用程序。我需要设计父子网格。我能够在RowDetailsVisibilityChanged事件中显示子网格。但是当我点击网格中的展开按钮时,我想要触发该事件,请在点击事件中提供给孩子网格穿鞋的代码....请查看我的代码以给出正确和适当的答案





 <   DataGrid      >  
< DataGrid.Columns > ;
< DataGridTemplateColumn 标题 = C >
< DataGridTemplateColumn.CellTemplate >
< < span class =code-leadattribute> DataTemplate >
< StackPanel >
< 按钮 x:名称 = btnCollapse 工具提示 = 展开 前景 = 黑色 背景 = 透明 BorderBrush = 透明 标记 = {Binding LineItemKitsID} >
< 图片 来源 = < span class =code-keyword> ../ images / Plus.png 光标 = 高度 = 20 宽度 = 15 < span class =code-keyword>> < / Image >
< /按钮 < span class =code-keyword>>
< / StackPanel >
< / DataTemplate >
< / DataGridTemplateColumn.CellTemplate >
< / DataGridTemplateColumn >

< DataGridTextColumn CanUserReorder = True CanUserResize = < span class =code-keyword> True CanUserSort = True 宽度 = 160 * Binding = < span class =code-keyword> {Binding GroupName} 标题 = 组名 前景 = 黑色 >
< / DataGridTextColumn >


< / DataGrid.Columns >
< DataGrid.RowDetailsTemplate >
< DataTemplate >
< StackPanel 方向 = 水平 >
< DataGrid 名称 = < span class =code-keyw ord> NestedDG >
< DataGrid.Columns >
< DataGridTextColumn CanUserReorder = True CanUserResize = < span class =code-attribute> CanUserSort = True 宽度 = 230 绑定 = {绑定LineItem} 标题 = 行项目 前景 = 黑色 >
< / DataGridTextColumn >



< DataGridTextColumn CanUserReorder = True CanUserResize = True CanUserSort = True 宽度 = 110 绑定 = {Binding EffectiveDate} 标题 = 生效日期 前景 = 黑色 >
< / DataGridTextColumn >



< span class =code-keyword>< / DataGrid.Columns >

< / DataGrid > ;
< / StackPanel >
< / DataTemplate >
< / DataGrid.RowDetai lsTemplate >









c#code:

它会在

 RowDetailsVisibilityChanged 

中触发..但是我想按下按钮点击< br $> b $ b

 受保护  void  ParentDG_RowDetailsVisibilityChanged( object  sender,DataGridRowDetailsEventArgs e)
{
DataGrid nestedGrid =(DataGrid)e.DetailsElement.FindName( NestedDG);
if (e.Row.DetailsVisibility == Visibility.Visible)
{
nestedGrid.ItemsSource = dsKitDetails.Tables [ 0 ]默认视图。
}

}

解决方案

关注这篇文章:



https://social.msdn.microsoft.com/Forums/vstudio/en-US/2cde5655-4b8d-4a12-8365-bb0e4a93546f/activating-input- controls-inside-datagrids-rowdetailstemplate-with-click?forum = wpf [ ^ ]

Hello,
I am designing a wpf application.I got a requirement to design Parent child grid. I am able to show the child grid in RowDetailsVisibilityChanged event. But I want to fire that event when I click a expand button in my grid, Please provide me the code to shoe the child grid in click event.... Please see my code to give the correct and appropriate answer


<DataGrid  >
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="C">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                 <StackPanel>
                        <Button x:Name="btnCollapse"  ToolTip="Expand" Foreground="Black" Background="Transparent" BorderBrush="Transparent" Tag="{Binding LineItemKitsID}"   >
                                        <Image Source="../images/Plus.png" Cursor="Hand" Height="20" Width="15" ></Image>
                                    </Button>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="160*" Binding="{Binding GroupName}" Header="Group Name"  Foreground="Black">
                    </DataGridTextColumn>


                </DataGrid.Columns>
    <DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <DataGrid Name="NestedDG">
                    <DataGrid.Columns>
                        <DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="230" Binding="{Binding LineItem}" Header="Line Item"  Foreground="Black">
                        </DataGridTextColumn>
                      


                        <DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="110" Binding="{Binding EffectiveDate}" Header="Effective Date"  Foreground="Black">
                        </DataGridTextColumn>

                       
                   
                    </DataGrid.Columns>

                </DataGrid>
            </StackPanel>
        </DataTemplate>
    </DataGrid.RowDetailsTemplate>





c# code :
It will fire in

RowDetailsVisibilityChanged

.. but i want to fire in button click

protected void ParentDG_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
           {
            DataGrid nestedGrid = (DataGrid)e.DetailsElement.FindName("NestedDG");
              if (e.Row.DetailsVisibility == Visibility.Visible)
              {
                  nestedGrid.ItemsSource = dsKitDetails.Tables[0].DefaultView;
              }

            }

解决方案

Follow this article:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/2cde5655-4b8d-4a12-8365-bb0e4a93546f/activating-input-controls-inside-datagrids-rowdetailstemplate-with-single-click?forum=wpf[^]


这篇关于wpf中的父子网格问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆