I have a TabControl with two ContentTemplates:
<TabControl ItemsSource="{Binding Tabs}" ContentTemplateSelector="{StaticResource TabSelector}">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding TabName}" HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
And my two templates are two user controls:
<UserControl.Resources>
<ResourceDictionary>
<DataTemplate x:Key="UserListTemplate">
<uc:UserList />
</DataTemplate>
<DataTemplate x:Key="UserContentTemplate">
<uc:User />
</DataTemplate>
<uc:TabSelector x:Key="TabSelector" UserListTemplate="{StaticResource UserListTemplate}" UserContentTemplate="{StaticResource UserContentTemplate}" />
</ResourceDictionary>
</UserControl.Resources>
I'm setting the DataContext in the XAML:
<UserControl.DataContext>
<local:ViewUsers />
</UserControl.DataContext>
The TabControl bind is working, showing all the tabs as I add/remove from the collection, but how do I get the DataContext in my UserControls? The DataContext is always null when the UserControl is started.
Aucun commentaire:
Enregistrer un commentaire