I have a TabControl with ItemsSource set to ObservableCollection<BookTab> and using ContentTemplateSelector to create different tabs.
class BookTab { public string Name { get; set; } public string Type { get; set; } public object Data { get; set; } } <TabControl Name="tabControl" ContentTemplateSelector="{StaticResource tabTemplateSelector}"> <TabControl.ItemContainerStyle> <Style TargetType="TabItem"> <Setter Property="Header" Value="{Binding Name}"/> <Setter Property="Content" Value="{Binding}"/> </Style> </TabControl.ItemContainerStyle> </TabControl>
The type in BookTab defines the DataTemplate used on the corresponding tab, the Name is displayed in the header of the tab, and the data should be displayed in the contents of the tabs, that is, in the DataGrid. Data is set to ObservableCollections for different types.
A DataTemplate might look like this:
<DataTemplate x:Key="bookTabTemplate"> <TabItem Name="bookTab"> <Grid> <DataGrid Name="bookGrid"> ... </DataGrid> </Grid> </TabItem> </DataTemplate>
I tried different ways to bind the Data property to a DataGrid ItemsSource, but all I got is a grid displaying the word "Book" (the value of the BookTab Name property). I assume that I need to somehow extend the TabControl binding to the DataGrid, but I cannot figure it out.
source share