Skip to content

Grid.IsSharedSizeScope makes star-width columns not work #19114

Open
@ArcanoxDragon

Description

@ArcanoxDragon

Describe the bug

I have a view with a two-column grid representing a vertical stack of "label-value" control pairs. I plan on adding additional grids below it (conditionally, based on bindings). I would like the grids to all share the same column sizes so the labels line up across all grid. However, when I place Grid.IsSharedSizeScope="True" on the parent container of the grids, the right-most column (with Width="*") fails to size controls correctly. The controls start behaving as though they have HorizontalAlignment="Left" even though they have the default of HorizontalAlignment="Stretch" (explicitly setting it to Stretch does not fix the issue).

This is the relevant AXAML so far:

<Panel>
	<Grid
		RowDefinitions="35,35,35,35"
		ShowGridLines="True"
		VerticalAlignment="Top">
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
			<ColumnDefinition Width="*" SharedSizeGroup="Value" />
		</Grid.ColumnDefinitions>

		<Label Grid.Row="0" Grid.Column="0" Target="PositionXTextBox">
			Position:
		</Label>

		<NumericUpDown Grid.Row="0" Grid.Column="1"
					   x:Name="PositionXTextBox"
					   Value="{Binding #Control.ViewModel.PositionX}"
					   Watermark="{Binding #Control.ViewModel.PositionXWatermark}"
					   Increment="0.01">
			<NumericUpDown.InnerLeftContent>
				<Label Margin="4,0,0,0"
					   Target="PositionXTextBox"
					   VerticalContentAlignment="Center">
					X
				</Label>
			</NumericUpDown.InnerLeftContent>
		</NumericUpDown>

		<NumericUpDown Grid.Row="1" Grid.Column="1"
					   x:Name="PositionYTextBox"
					   Value="{Binding #Control.ViewModel.PositionY}"
					   Watermark="{Binding #Control.ViewModel.PositionYWatermark}"
					   Increment="0.01">
			<NumericUpDown.InnerLeftContent>
				<Label Margin="4,0,0,0"
					   Target="PositionYTextBox"
					   VerticalAlignment="Center">
					Y
				</Label>
			</NumericUpDown.InnerLeftContent>
		</NumericUpDown>

		<Label Grid.Row="2" Grid.Column="0" Target="SizeXTextBox">
			Size:
		</Label>

		<NumericUpDown Grid.Row="2" Grid.Column="1"
					   x:Name="SizeXTextBox"
					   Value="{Binding #Control.ViewModel.SizeX}"
					   Watermark="{Binding #Control.ViewModel.SizeXWatermark}"
					   Increment="0.01">
			<NumericUpDown.InnerLeftContent>
				<Label Margin="4,0,0,0"
					   Target="SizeXTextBox"
					   VerticalContentAlignment="Center">
					X
				</Label>
			</NumericUpDown.InnerLeftContent>
		</NumericUpDown>

		<NumericUpDown Grid.Row="3" Grid.Column="1"
					   x:Name="SizeYTextBox"
					   Value="{Binding #Control.ViewModel.SizeY}"
					   Watermark="{Binding #Control.ViewModel.SizeYWatermark}"
					   Increment="0.01">
			<NumericUpDown.InnerLeftContent>
				<Label Margin="4,0,0,0"
					   Target="SizeYTextBox"
					   VerticalAlignment="Center">
					Y
				</Label>
			</NumericUpDown.InnerLeftContent>
		</NumericUpDown>
	</Grid>
</Panel>

(this is a trimmed down version of what's in my actual application, but I verified it still reproduces the issue)

This results in the following:

Image

If I place Grid.IsSharedSizeScope="True" on the Panel, it instead results in the following:

Image

To Reproduce

Place the example AXAML into a user control. Observe that the previewer displays the grid correctly as in my first screenshot (text boxes stretched). The behavior should be the same when running the program.

Now add Grid.IsSharedSizeScope="True" to the Panel element. Observe that the previewer now shows the text boxes shrunk against the left side, as if they are left-aligned. The behavior should be the same when running the program.

Expected behavior

The text boxes should be sized exactly the same with or without Grid.IsSharedSizeScope="True" on the parent container, and the correct (stretched) size should be shared amongst all neighboring grids in the same shared size scope.

Avalonia version

11.3.2

OS

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions