需要两个属性:
1. Grid.IsSharedSizeScope="True"
2. SharedSizeGroup=名称
<StackPanel Margin="15" Grid.IsSharedSizeScope="True"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="A"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto" SharedSizeGroup="B"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="Col 1"/> <TextBox Grid.Column="1" /> <TextBlock Grid.Column="2" Text="3rd column here"/> </Grid> <Separator Margin="0,20"/> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="A"/> <ColumnDefinition /> <ColumnDefinition SharedSizeGroup="B"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="1"/> <TextBox Grid.Column="1"/> </Grid> </StackPanel>
原文地址:https://www.cnblogs.com/xpvincent/p/9525349.html
时间: 2024-11-02 00:15:06