使用WPF中的网格(Grid),可以设计出类似于这样的界面吗?设计列非常容易,但是行如何呢?还是有其他更好的解决方案,比如另一个容器?请想象每个矩形框都是一个模块(GroupBox)。
创建一个有两列的外部网格。在这个网格中,每列放置一个网格。这将导致所需的布局。
以下是如何操作的示例。请注意,我已经为高度放置了一些星号。根据您的需要进行相应更改。
<Grid>
<Grid.ColumnDefinitions>
<Grid.ColumnDefinition Width="*" />
<Grid.ColumnDefinition Width="*" />
<Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Here content elements of the first column -->
</Grid>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Here content elements of the second column -->
</Grid>
</Grid>
定义你的列和行。
将每个 Groupbox
放在所需的行和列上,并设置其 rowspan
,以定义它跨越多少行。