How to bind items of a TabControl to an observable collection in wpf?

后端 未结 1 560
情深已故
情深已故 2020-12-09 03:23

What is the simplest example of binding the items of a TabControl to an ObservableCollection?

Each tab\'s content will have unique data, and indeed this data will ha

相关标签:
1条回答
  • 2020-12-09 03:35

    Basic example :

    <Window.Resources>
    
        <DataTemplate x:Key="templateForTheContent" DataType="{x:Type vm:TheViewModelType}">
            <v:YourUserControl/>
        </DataTemplate>
    
        <DataTemplate x:Key="templateForTheHeader" DataType="{x:Type vm:TheViewModelType}">
            <TextBlock Text="{Binding ThePropertyToDisplayInTheHeader}"/>
        </DataTemplate>
    
    </Window.Resources>
    
    ...
    
    <TabControl ItemsSource="{Binding YourCollection}"
                ContentTemplate="{StaticResource templateForTheContent}"
                ItemTemplate="{StaticResource templateForTheHeader}">
    </TabControl>
    
    0 讨论(0)
提交回复
热议问题