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
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
tag to the
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:
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.)
TabControl использует специализированный класс TabPanel, а не общую панель, такую как StackPanel, потому что, если вы возитесь с TabControl, вы поймете, что панель делает довольно много вещей, которых не делают обычные панели. Один из них - это настройка элементов заголовка вкладки в нескольких строках. Другой заключается в том, что строки элементов будут переупорядочены так, чтобы выбранный заголовок элемента табуляции всегда находился в последней строке. Я предполагаю, что это могло бы сделать даже больше
. Мне очень интересно узнать, почему размещение стиля в разделе ресурсов окна не работает. Моя первоначальная реакция была такова, что он должен работать, пока я не попробую. Я добавляю это как ответ, потому что ТАК не позволяет мне добавлять изображение в комментарий.
Для этого вам, вероятно, потребуется создать ControlTemplate.
Я еще не очень хорошо знаком с ControlTemplates. Я взломал этот пример из: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.tabpanel.aspx
<Style TargetType="{x:Type TabControl}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TabPanel Name="HeaderPanel"
Grid.Row="0"
Panel.ZIndex="1"
Margin="0,0,4,-1"
IsItemsHost="True"
KeyboardNavigation.TabIndex="1"
HorizontalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>