本文介绍了在另一个Datagrid的RowDetailsTemplate中使用Datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在另一个Datagrid的RowDetailsTempalte中使用DataGrid。这个内部Datagrid应该将其列绑定到外部Datagrid中当前对象的属性。例如,如果外部Datagrid以名字和姓氏显示所有联系人,如果我选择一行,我应该能够看到另一个包含与该联系人相关联的所有电话号码的Datagrid。我最感兴趣的是内部Datagrid的数据如何绑定到外部Datagrid的数据。这是一些我以前开始的XAML:

 < data:DataGrid MinHeight =700x:名称=contacts> 
< data:DataGrid.Columns>
< data:DataGridTextColumn Header =First NameBinding ={Binding FirstName}>< / data:DataGridTextColumn>
< data:DataGridTextColumn Header =Last NameBinding ={Binding LastName}>< / data:DataGridTextColumn>
< / data:DataGrid.Columns>
< data:DataGrid.RowDetailsTemplate>
< DataTemplate>
< StackPanel Background =Black>
< StackPanel Background =WhiteMargin =16>
< data:DataGrid DataContext =Contact.Phones>

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


解决方案

此线程的最后一个答案帮助了我:。


$ b $在内部的DataGrid我设置 ItemsSource ={Binding Phones}并删除 DataContext 。 / p>

I would like to use a DataGrid within the RowDetailsTempalte of another Datagrid. This inner Datagrid should have its columns bound to a property of the current object in the outer Datagrid. For example, if the outer Datagrid is displaying all contacts by first name and last name, if I select a row I should be able to see another Datagrid containing all phone numbers associated with that contact. What I am most interested in is how the data of the inner Datagrid binds to the data of the outer Datagrid. Here is some XAML that I have so far to start with:

<data:DataGrid MinHeight="700" x:Name="contacts">
                <data:DataGrid.Columns>                       
                    <data:DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"></data:DataGridTextColumn>
                    <data:DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"></data:DataGridTextColumn>                        
                 </data:DataGrid.Columns>
                <data:DataGrid.RowDetailsTemplate>
                    <DataTemplate>
                        <StackPanel Background="Black">
                            <StackPanel Background="White" Margin="16">
                                <data:DataGrid DataContext="Contact.Phones">

                                </data:DataGrid>
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </data:DataGrid.RowDetailsTemplate>
            </data:DataGrid>
解决方案

The last answer on this thread helped me: How is access inner Datagrid in Silverlight?.

On the inner DataGrid I set ItemsSource="{Binding Phones}" and removed the DataContext.

这篇关于在另一个Datagrid的RowDetailsTemplate中使用Datagrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 11:32