例如我可以做这样的事情:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Width="Auto">
<RowDefinition Width="Auto">
<RowDefinition Width="Auto">
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0">Header 1</TextBlock>
<TextBox Grid.Row="0" Grid.Column="1" MaxLines="1" />
<Button Grid.Row="0" Grid.Column="2">Send</Button>
<Button Grid.Row="0" Grid.Column="3">Save</Button>
<TextBlock Grid.Row="1" Grid.Column="0">Header 2</TextBlock>
<TextBox Grid.Row="1" Grid.Column="1" MaxLines="1" />
<Button Grid.Row="1" Grid.Column="2">Send</Button>
<Button Grid.Row="1" Grid.Column="3">Save</Button>
<TextBlock Grid.Row="2" Grid.Column="0">Header 3</TextBlock>
<TextBox Grid.Row="2" Grid.Column="1" MaxLines="1" />
<Button Grid.Row="2" Grid.Column="2">Send</Button>
<Button Grid.Row="2" Grid.Column="3">Save</Button>
</Grid>
或者我可以这样做:
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock>Header 1</TextBlock>
<TextBox MaxLines="1" />
<Button>Send</Button>
<Button>Save</Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock>Header 2</TextBlock>
<TextBox MaxLines="1" />
<Button>Send</Button>
<Button>Save</Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock>Header 3</TextBlock>
<TextBox MaxLines="1" />
<Button>Send</Button>
<Button>Save</Button>
</StackPanel>
<StackPanel>
除了我希望能够像在 StackPanel 中一样轻松地操作行(添加新行、移动行等),同时像在 Grid 中一样保持列正确对齐。