[英]WPF HeaderContent Control Vertical Alignment
How can I get HCC using a tab control to "Stretch" all the way down vertically? 如何使用选项卡控件将HCC一直垂直向下“拉伸”? How can I achieve this?
我怎样才能做到这一点?
Here is the header content control XAML: 这是标题内容控件XAML:
<HeaderedContentControl
Content="{Binding Path=Workspaces}"
ContentTemplate="{StaticResource WorkspacesTemplate}" />
Here is the corresponding style info: 这是相应的样式信息:
<DataTemplate x:Key="WorkspacesTemplate">
<TabControl
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource ClosableTabItemTemplate}"
Margin="4"
/>
</DataTemplate>
<DataTemplate x:Key="ClosableTabItemTemplate">
<DockPanel>
<Button
Command="{Binding Path=CloseCommand}"
Content="X"
Cursor="Hand"
DockPanel.Dock="Right"
Focusable="False"
FontFamily="Arial"
FontSize="9"
FontWeight="Bold"
Margin="0,1,0,0"
Padding="0"
VerticalContentAlignment="Bottom"
Width="16" Height="16"
/>
<ContentPresenter
Content="{Binding Path=DisplayName}"
/>
</DockPanel>
If you examine the control template for the HeaderedContentControl you'll find it puts the content in a StackPanel which is why content isn't stretching vertically. 如果检查HeaderedContentControl的控件模板,您会发现它将内容放在StackPanel中,这就是内容不是垂直拉伸的原因。 This is the default template:
这是默认模板:
<Style x:Key="HeaderedContentControlStyle"
TargetType="{x:Type HeaderedContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type HeaderedContentControl}">
<StackPanel>
<ContentPresenter ContentSource="Header"/>
<ContentPresenter/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
So if we replace the StackPanel with a Grid like this: 因此,如果我们用这样的Grid替换StackPanel:
<Style x:Key="HeaderedContentControlStyle"
TargetType="{x:Type HeaderedContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type HeaderedContentControl}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ContentPresenter ContentSource="Header"/>
<ContentPresenter Grid.Row="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
and use that style 并使用那种风格
<HeaderedContentControl
Style="{StaticResource HeaderedContentControlStyle}"
Content="{Binding Path=Workspaces}"
ContentTemplate="{StaticResource WorkspacesTemplate}" />
then the content should stretch vertically. 那么内容应该垂直伸展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.