在 WPF TabControl 上 - 我可以在选项卡标题旁边添加内容吗? [英] On the WPF TabControl - can I add content next to the tab headers?
本文介绍了在 WPF TabControl 上 - 我可以在选项卡标题旁边添加内容吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法可以将另一个控件(即按钮)内联放置在 WPF 中的选项卡标题的右侧?
Is there an easy way to position another control (i.e. a button) inline and to the right of tab headers in WPF?
在网络中,我会使用浮动或绝对定位来实现这一点.
In the web, I would use a float or absolute positioning to accomplish this.
这张图片中的红线是我想要达到的:
(来源:jonkragh.com)子>
The red line in this picture is what I am trying to get to:
(source: jonkragh.com)
谢谢!乔恩
推荐答案
实现此目的的可靠方法是重新模板化 TabControl
,就像我对 ActiveAwareCommand
示例:
The robust way to do this is to re-template the TabControl
as I did for the close button in my ActiveAwareCommand
sample:
<ControlTemplate x:Key="TabControlTemplate" TargetType="TabControl">
<Grid 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>
<Grid Panel.ZIndex="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TabPanel Margin="2,2,2,0" x:Name="HeaderPanel" IsItemsHost="true" KeyboardNavigation.TabIndex="1"/>
<Button Grid.Column="1" Command="{Binding DataContext.CloseCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">X</Button>
</Grid>
<Border x:Name="ContentPanel" Grid.Column="0" Grid.Row="1" BorderBrush="#D0CEBF" BorderThickness="0,0,1,1" KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Border Background="{TemplateBinding Background}">
<Grid x:Name="PART_ItemsHolder"/>
</Border>
</Border>
</Border>
</Grid>
</ControlTemplate>
请注意 TabPanel
和 Button
如何永远不会重叠.结果:
Notice how the TabPanel
and Button
can never overlap. Result:
这篇关于在 WPF TabControl 上 - 我可以在选项卡标题旁边添加内容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文