Nesting Wrappanel into DataGrid

689 views Asked by At

I am trying to nest a WrapPanel inside a DataGrid cell. What am I missing?

This is used to display sports team information. A Team has a TeamName, a Coach, a Roster of Players where each player has a FullName.

More technically speaking, the Roster property is a ObservableCollection where PlayerViewModel has FullName property.

<DataGrid ItemsSource="{Binding Teams}">
   <DataGrid.Columns>
      <DataGridTextColumn Header="Team Name" Binding="{Binding TeamName}" />
      <DataGridTextColumn Header="Coach" Binding="{Binding Coach}" />
      <DataGridTemplateColumn>
         <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
               <WrapPanel DataContext="{Binding Roster}">
                  <Label Content="{Binding FullName}">
               </WrapPanel>
            </DataTemplate>
         </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>
   </DataGrid.Columns>
</DataGrid>
1

There are 1 answers

0
bartonm On

I figured it out. This worked.

<DataGridTemplateColumn Width="150">
   <DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
         <WrapPanel DataContext="{Binding Roster}">
            <Label HorizontalAlignment="Center" Content="{Binding Path=FirstName}" />
         </WrapPanel>
      </DataTemplate>
   </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>