gpt4 book ai didi

wpf - TabItem 标题 : Content doesn't stretch if the actual tab header does

转载 作者:行者123 更新时间:2023-12-04 17:12:15 25 4
gpt4 key购买 nike

我有一个 TabControl 并试图让标题看起来不错。我有以下 XAML:

(在 Resources.xaml :)

<DataTemplate x:Key="ClosableTabItemTemplate">
<DockPanel LastChildFill="True" MinWidth="200" Height="20" HorizontalAlignment="Stretch" behaviors:MouseClickBehavior.ClickCommand="{Binding Path=CloseCommand}">
<Image Source="{Binding Path=Image}" Height="16" VerticalAlignment="Center" />
<Button Background="Transparent"
BorderBrush="Transparent"
Command="{Binding Path=CloseCommand}"
Content="X"
Cursor="Hand"
DockPanel.Dock="Right"
Focusable="False"
FontSize="9"
FontWeight="Bold"
Margin="3,0,0,0"
Padding="0"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Width="16" Height="16" />
<TextBlock Text="{Binding Path=Header}" DockPanel.Dock="Left" VerticalAlignment="Center" />
</DockPanel>
</DataTemplate>

(在 MainWindow.xaml :)
<TabControl Grid.Column="1"
ItemsSource="{Binding Path=Tabs}"
ItemTemplate="{DynamicResource ClosableTabItemTemplate}" />

这是我的问题的视觉示例:



我现在喜欢选项卡的实际宽度,但我的页眉停靠面板并没有填满所有空间这一事实令人烦恼。如果我使用 Grid 也会发生同样的事情,也是(可能是任何容器控件)。

最佳答案

ContentPresenter.HorizontalAlignment TabItem 的默认样式绑定(bind)到 ItemsControl.HorizontalContentAlignment .取自 Aero.NormalColor.xaml:

<ContentPresenter Name="Content"
ContentSource="Header"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
HorizontalAlignment="{Binding Path=HorizontalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
VerticalAlignment="{Binding Path=VerticalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
RecognizesAccessKey="True"/>

设置 TabControl.HorizontalContentAlignmentStretch为我解决了这个问题。
<TabControl HorizontalContentAlignment="Stretch" />

关于wpf - TabItem 标题 : Content doesn't stretch if the actual tab header does,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7499582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com