1
votes

I have been searching around without finding a fix so here I go.

I have a Windows with a center that contain a UserControl that will fill the general area of my application.

I have a TabControl with multiple TabItem. In each TabItem I have to show different controls including Datagrids.

Here is the sample code of my second TabItem.

<TabItem Header="Suivi" IsSelected="True">
  <Grid Background="#FFE5E5E5" >
    <DataGrid x:Name="dgSuivi" ItemsSource="{Binding Source=Suivi}" >
      <DataGrid.Columns>
      <DataGridTextColumn Header="Suivi" Binding="{Binding COD_NOM }" />
      <DataGridTextColumn Header="Date planifiée" Binding="{Binding DAT_PLAN}" />
      <DataGridTextColumn Header="Date révisée" Binding="{Binding DAT_REVIS}"  />
      <DataGridTextColumn Header="Date réelle" Binding="{Binding DAT_REEL}" />
    </DataGrid.Columns>
  </DataGrid>
 </Grid>
</TabItem>

My code behind has a filled property called Suivi

Public Property Suivi As ObservableCollection(Of MyType)

and MyType is the following class:

Public Class MyType

 Property COD_NOM as String

 Property DAT_PLAN as DateTime

 Property DAT_REVIS as DateTime

 Property DAT_REEL as DateTime

 Public Sub New()

  COD_NOM_DAT = Nothing
  DAT_PLAN = New System.DateTime(9999, 1, 1)
  DAT_REVIS = New System.DateTime(9999, 1, 1)
  DAT_REEL = New System.DateTime(9999, 1, 1)

 End Sub

End Class

When I change to the second TabItem (Suivi) the datagrid is filled with empty lines.

I've been searching to fix this but I think I am missing a notion here. Is my binding done right?

1
One thing springs to mind: You are binding with a Source of Suivi. What is that? I would have expected you to set the DataContext, and do {Binding Path=Suivi}. - Troels Larsen
post the tab that is working - paparazzo

1 Answers

0
votes

Thanks for the comments! That made me think, what made the first one work? I was sure it was my binding to my observable collection but i've been wrong.

What I was missing is the assignation of the ItemsSource... Suivi = New ObservableCollection(Of MyType)(MyList) dgSuivi.ItemsSource=Suivi

it does work now...

Thank you and I hope this can be usefull for other out there.