WPF TabControl 选项卡在下内容在上
要在WPF TabControl中将选项卡放在下面,而内容放在上面,可以使用下面的方法:
- 创建一个自定义控件模板,使用HorizontalAlignment="Stretch"将选项卡放在底部。
<Style TargetType="{x:Type TabControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TabPanel Grid.Row="1" Panel.ZIndex="1" Margin="0,-1,0,0" IsItemsHost="True" />
<ContentPresenter Grid.Row="0" ContentSource="Header" />
<ContentPresenter Grid.Row="1" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
- 在TabItem上使用VerticalAlignment="Top"将内容放在顶部。
<TabControl>
<TabItem Header="Tab 1">
<Grid VerticalAlignment="Top">
<TextBlock Text="Content of Tab 1" />
</Grid>
</TabItem>
<TabItem Header="Tab 2">
<Grid VerticalAlignment="Top">
<TextBlock Text="Content of Tab 2" />
</Grid>
</TabItem>
</TabControl>
原文地址: https://www.cveoy.top/t/topic/bY9h 著作权归作者所有。请勿转载和采集!