开发者

Append DataGrid inside of DataGrids RowDetailsTemplate

开发者 https://www.devze.com 2023-01-01 04:30 出处:网络
this appears to bind, but rows in Details Grid are empty. Something is off/missing? I\'ve also tried {Binding Sub开发者_Python百科Customers}

this appears to bind, but rows in Details Grid are empty. Something is off/missing?

I've also tried {Binding Sub开发者_Python百科Customers}

SubCustomers is a List on parent object.

I am able to bind this way to single Fields such as FirstName etc.. just not the subcollection..

        <DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <DataGrid AutoGenerateColumns="True" ItemsSource="{Binding Source=SubCustomers}" />
            </DataTemplate>
        </DataGrid.RowDetailsTemplate>


The problem is that you are trying to bind to a property on the DataContext of the parent, not on that particular row. So, the DataContext of the RowDetails is the row item, and in order to get the parent's property, you need to use RelativeSource bindings. If you bind to the DataContext of the parent, you can then "dot-down" to the property you actually care about:

<DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <DataGrid AutoGenerateColumns="True" 
                      ItemsSource="{Binding DataContext.SubCustomers, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
        </DataTemplate>
    </DataGrid.RowDetailsTemplate>
0

精彩评论

暂无评论...
验证码 换一张
取 消