WPF 选项卡样式:将选项卡放置在底部,内容放置在顶部
以下是一个示例样式,可以让WPF选项卡向下,内容向上:
<Style TargetType="TabControl">
<Setter Property="TabStripPlacement" Value="Bottom"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TabPanel Grid.Row="1"
Margin="0,-1,0,0"
IsItemsHost="True"
KeyboardNavigation.TabIndex="1"
Background="White"/>
<Border Grid.Row="0"
Background="White"
BorderBrush="Gray"
BorderThickness="0,0,0,1">
<ContentPresenter ContentSource="Header"
Margin="5,0,0,0"/>
</Border>
<ContentPresenter Grid.Row="1"
ContentSource="SelectedContent"
Margin="0,-1,0,0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这个样式将选项卡的TabStripPlacement属性设置为Bottom,将标签放在底部。然后,它定义了一个Grid,其中第一行包含选项卡标签,第二行包含选定的内容。
注意,这个样式假设选项卡的Header属性已经设置为要显示的标签文本。如果你使用了自定义标签模板,你需要在ContentPresenter中使用ContentTemplate属性来指定模板。
原文地址: https://www.cveoy.top/t/topic/nkwy 著作权归作者所有。请勿转载和采集!