Here's a newbie question on the WPF TabControl, TabItem and TabPanel. There is a related question on StackOVF with an answer I happily used in my app. Here's a link to the answer, and the code snippet as well:
WPF: Center TabItems in a 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 wonderful, I'd love to move the Resources and Style stuff to a better location (a stylesheet or the like). My first attempt was to move the <TabControl.Resources>
tag to the <Window.Resources>
but this did not work. I tried several variations but couldn't get it to work. Here's an example of an attempt I somewhat expected to work:
<!-- Doesn't work as expected: -->
<Window.Resources>
<Style TargetType="{x:Type TabPanel}">
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
</Window.Resources>
Searching the web and msdn didn't help me solve my problem, but instead left me with a second (related) question: what actually is a TabPanel, and how does it relate to the TabControl?
Any help and tips would be much appreciated.
(Edited: commented in last example that the code doesn't work for me.)
<TabPanel />
element to the TabControl. (Edited comment) – Raising