views:

12

answers:

2

So I have the following xaml The parent list view is bound to collection programmatically All of the binding works great except for the datagrid doesn't populate. Is there an additional step I need to take or should I just cheat and bind it on the back end.

<ListView.ItemTemplate>
            <DataTemplate>
                <Border BorderBrush="DarkSlateGray" BorderThickness="2">
                    <StackPanel Orientation="Vertical">
                        <DockPanel>
                            <Label TextBlock.FontWeight="ExtraBold" FontSize="14" DockPanel.Dock="Left">Message</Label>
                            <Label Content="{Binding FriendlyMessageText}"></Label>
                        </DockPanel>
                        <DockPanel>
                            <Label TextBlock.FontWeight="ExtraBold" FontSize="14" DockPanel.Dock="Left">Status</Label>
                            <Label Content="{Binding Status }"></Label>

                        </DockPanel>

                        <DataGrid Height="80" ItemsSource="{Binding AssocatedMessages }">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Text" Width="*" Binding="{Binding Path=FriendlyMessageText}" >

                                </DataGridTextColumn>
                                <DataGridTextColumn Header="Status Code"   Binding="{Binding  Path=StatusCode}" />
                                <DataGridTextColumn Header="Entity ID" Binding="{Binding EntityID}" />
                                <DataGridTextColumn Header="Category Code" Binding="{Binding CategoryCode }" />
                            </DataGrid.Columns>

                        </DataGrid>



                    </StackPanel>
                </Border>
            </DataTemplate>
        </ListView.ItemTemplate>
+1  A: 

Hi,

Without having full complete knowledge of your code this is kind of a shot in the dark. When you set the ItemsSource for the DataGrid to AssocatedMessages (it is probably mispelled), you are setting the DataContext for all children to the AssocatedMessages collection.

So, if you bind to FriendlyMessageText in a DG column (assuming it is a property from the ListView's Data Source, as you are binding to that in a label outside the DG), the binding engine won't be able to find that property.

To check if this is happening, try debugging the bindings as explained in this post.

I hope this helps.

Thanks, Damian

Damian Schenkelman
It was misspelled in the object which I didn't notice until you pointed it out :). Good blog post btw +1
rerun
all so AssociatedMessages is a property that returns a collection
rerun
A: 

I didn't set the data context on the parent control when I set the itemsource of the parent list box.

rerun