How does WPF TabControl Template working?
How does WPF TabControl Template working?
Today , i try to write a ControlTemplate for TabControl , and i use Blend to check out the standard XAML of TabControl , here is the template xaml code:
xaml
<Style x:Key="TabControlStyle1" TargetType="x:Type TabControl">
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type TabControl">
<Grid x:Name="templateRoot" ClipToBounds="True" SnapsToDevicePixels="True" KeyboardNavigation.TabNavigation="Local">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0"/>
<ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto"/>
<RowDefinition x:Name="RowDefinition1" Height="*"/>
</Grid.RowDefinitions>
<TabPanel x:Name="HeaderPanel" Background="Transparent" Grid.Column="0" IsItemsHost="True" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/>
...
</Grid>
<ControlTemplate.Triggers>
...
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Just like the xaml code descirbed , thers is a "TabPanel" in the template , which contains all the "TabItems". And if i want to redefine the layout mode of "TabItmes" , i just need to replace the "TabPanel" with some other Panel , like "StackPanel","Grid" and so on ....
Here comes the question , how does "WPF" kown that all the "TabItems" should be put into the "TabPanel" , "StackPanel" or "Grid"? Are there any rules inside?
<ContentPresenter />
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
It doesn't. You need to put a
<ContentPresenter />
in somewhere for it to know where to put the content.– chancea
Aug 22 at 17:22