Question

In my application I have a main window composed by some menus and menu-items and a TabControl. In Window.DataContext, I reference my ViewModel that contains a property of type ObservableCollection<MyItemModel> named Items.

My TabControl.ItemsSource is bound to the Items property so the TabItems are declared dynamicaly:

<Window>
...
<Window.DataContext>
<local:ViewModel x:Name="model" />
</Window.DataContext>

...

<TabControl ItemsSource="{Binding Items}" />

</Window>

Now I want to define a Style for my TabItems in App.xaml like this:

<App.xaml>
...

<Style TargetType="{x:Type TabItem}" x:Key="MyTabItem">
...
</Style>

...
<App.xaml>

And use this Style in my Window. But the problem is how if TabControl does not have a property for ItemsStyle or something like this?

Was it helpful?

Solution

Have you tried

<TabControl ItemsSource="{Binding Items}" 
            ItemContainerStyle="{StaticResource MyTabItem}/>"

?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top