简体   繁体   中英

WPF SharedSizeGroup columns does not stretch

After setting SharedSizeGroup="B" to every second column of the subgrids. Column became unchangeable(always have one width) and width="1*" does not work. Is it possible to make that column resizeble but with SharedSizeGroup="B" .

 <Window x:Class="WpfApplication23ColumnsGroup.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid Grid.IsSharedSizeScope="True"> <Grid Height="100"> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid Grid.Row="0"> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="A"></ColumnDefinition> <ColumnDefinition Width="1*" SharedSizeGroup="B"></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <Label Content="Test"></Label> <TextBox Grid.Column="1" MinWidth="120" MaxWidth="240"></TextBox> <TextBox Grid.Column="2" MinWidth="120" MaxWidth="240"></TextBox> </Grid> <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="A"></ColumnDefinition> <ColumnDefinition SharedSizeGroup="B"></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <Label Content="TestTestTest"></Label> <TextBox Grid.Column="1"></TextBox> <TextBox Grid.Column="2"></TextBox> </Grid> <Grid Grid.Row="2"> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="A"></ColumnDefinition> <ColumnDefinition SharedSizeGroup="B"></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <Label Content="TestTestTestTestTestTest"></Label> <TextBox Grid.Column="1"></TextBox> <TextBox Grid.Column="2"></TextBox> </Grid> </Grid> </Grid> </Window>

From here :

You can set the width of a column in a Grid (or height of a row) in three different ways: auto, explicit size, or star sizing.

When you're using the SharedSizeGroup property to set multiple columns (or rows) to the same width (or height), the method that you use for setting the column width (or row height) affects the final size as follows:

  • Star sizing — not honored, treated as Auto
  • Absolute sizing — takes priority over Auto, columns are set to maximum explicit width
  • Auto sizing — if all columns are Auto, size is set to fit the largest content. If any columns use explicit width, the explicit width value takes precedence

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM