分层数据绑定不起作用wpf

时间:2013-08-29 21:56:45

标签: c# wpf data-binding telerik radgridview

我有这个代码,它基本上将gridview放在gridview的单元格下面 - 分层类型显示。

但子网格视图无法查看数据上下文。

我已经搜索并尝试了很多案例但它无法正常工作。我的程序现在抱怨绑定过程中发生的死锁和崩溃......我迷失了如何让数据绑定被我的孩子网格看到...

<telerik:RadGridView Height="633" HorizontalAlignment="Left" Margin="301,0,0,0" Name="radGridView2" VerticalAlignment="Top" Width="1546" Grid.Row="1" ShowGroupPanel="False" RowIndicatorVisibility="Collapsed" ItemsSource="{Binding Collections}" BorderBrush="#FFD7D2D2" FontFamily="Mangal" FontSize="14" Loaded="radGridView2_Loaded" AutoGenerateColumns="False"
                         RowStyleSelector="{StaticResource rowStyleSelector}" GroupRenderMode="Flat" ShowColumnSortIndexes="True" CanUserFreezeColumns="False" CanUserResizeColumns="False">
        <telerik:RadGridView.Columns>
            <telerik:GridViewToggleRowDetailsColumn />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding SetToPending}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding CollectionId}" ToolTip="{Binding Notes}"  />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding CollectionDate, Converter={StaticResource dateConverter}}"/>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding IsAdvancedPayment}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding LocationId}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding LocationName}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding NumMachines}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding NumCollections}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Gross}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding OperatorCommission}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Actual}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding OverShort}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Advance}" ToolTip="{Binding AdvanceId}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding TotalActualIn}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding TotalActualOut}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Gross}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding LocationCommission}" />
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Notes}" />
        </telerik:RadGridView.Columns>
        <telerik:RadGridView.RowDetailsTemplate>
            <DataTemplate>
                <telerik:RadGridView ItemsSource="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}" Name="childGrid" ShowGroupPanel="False">
                </telerik:RadGridView>
            </DataTemplate>
        </telerik:RadGridView.RowDetailsTemplate>
    </telerik:RadGridView>

1 个答案:

答案 0 :(得分:0)

我基本上找到了一个解决方案 - 子网格的DataContext是绑定到父网格的任何内容...因此绑定到父网格的集合是唯一的子网格看到的集合...所以我刚刚将它添加到我的数据上下文对象的集合中...但我很好奇,想知道如何使整个DataContext对子网格可见