【发布时间】:2011-07-28 21:17:29
【问题描述】:
我在我的 WPF 应用程序中使用以下代码作为组框:
<GroupBox Style="{StaticResource groupBoxStyle}" Header="RB" Margin="0,6,268,249" Name="groupBoxRB" HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="276">
此控件位于网格内,其定义如下:
<TabControl Grid.Row="1" Margin="4,12,0,12" Name="tabControl1" Background="Transparent">
<TabItem Style="{StaticResource tabItemMainStyle}" Header="Main" Name="tabItemMain" >
<Grid Background="Transparent" MinHeight="926" MinWidth="1218">
并且该选项卡控件位于主网格内:
<Window x:Class="SRM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:local="clr-namespace:SRM" ResizeMode="CanResize"
Title="SRM"
Width="991" Icon="Resources\Icons\SRM.png"
WindowStartupLocation="CenterScreen" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="1024" Height="774" Visibility="Visible" Foreground="#00000000" Margin="0">
<Grid Style="{StaticResource styleBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2.5" />
</Grid.ColumnDefinitions>
我不明白为什么我提到的 groupbox 不会在其垂直轴上伸展...有什么想法吗?
谢谢。
PS:静态资源没有定义高度/宽度/对齐方式
【问题讨论】:
-
您的
groupBoxStyle是否定义了自定义ControlTemplate?如果有,我们能看到吗? -
另外,如果去掉内部 Grid 中的 MinHeight 和 GroupBox 周围的大 Margin 是否还有问题?
-
groupBoxStyle 仅定义设置器(颜色/画笔/不透明度)。边距使组框不会相互重叠,但如果有更好的用途,它可以被替换。 Minheight 可以毫无问题地删除。
-
组框不相互重叠是什么意思?如果组框位于网格中,您可以使用列和行来控制布局,这样它们就不会相互重叠,我相信这是造成这个问题的大底边距。
-
@FatalBaboon,您是否尝试过使用Snoop 查看哪个项目没有拉伸(组框、网格或选项卡项目)?