Here's a newbie question for WPC TabControl, TabItem, and TabPanel. There is a related answer on StackOVF that I happily used in my application. Here is a link to the answer and a code snippet:
WPF: Center TabItems Tabs in TabControl
<TabControl> <TabControl.Resources> <Style TargetType="{x:Type TabPanel}"> <Setter Property="HorizontalAlignment" Value="Center" /> </Style> </TabControl.Resources> <TabItem Header="Test 1" /> <TabItem Header="Test 2" /> <TabItem Header="Test 3" /> <TabItem Header="Test 4" /> </TabControl>
While this is great, I would like to move resources and styles to a better place (style sheet, etc.). My first attempt was to move the <TabControl.Resources> to <Window.Resources> , but that didn't work. I tried several options, but could not get it to work. Here is an example of an attempt that I was expecting to work somewhat:
<Window.Resources> <Style TargetType="{x:Type TabPanel}"> <Setter Property="HorizontalAlignment" Value="Center" /> </Style> </Window.Resources>
Internet searches and msdn did not help me solve my problem, but instead left me a second (related) question: what is actually a TabPanel and how does it relate to TabControl
Any help and advice would be greatly appreciated.
(Edited: commented in the last example that the code is not working for me.)
wpf xaml tabcontrol tabpanel
Jeroen
source share