views:

104

answers:

2

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

I've also tried {Binding SubCustomers}

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>
A: 

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>
Abe Heidebrecht
thanks. That still does not work, and now instead of getting a grid in details with empty rows, i just get empty space. also,if DataContext of the parent is not of particular row, why does this work correctly? <TextBlock Text="{Binding FirstName}" />
Sonic Soul
The details is the row... I thought your SubCustomers was on the parent list (that doesn't make much sense, I know, but that is how I read your question). In that case, you should be able to bind directly to the list. Is the list populated at all times? If not, is it an ObservableCollection?
Abe Heidebrecht
A: 

oops I actually had the XAML right.

Abe helped me identify the real issue, which was that my SubCustomers collection was null. thanks Abe!

whew

Sonic Soul