Open
Description
Current behavior
If an AutoLayout
has children and they have HorizontalAlignment
set to Center
they won't display at the center, but at the left side. However if you dynamically (eg. button click) change their HorizontalAlignment
to Center
they will move to the center.
An UI update makes the AutoLayout
children return to the left. For example, given the following XAML:
<Grid>
<utu:AutoLayout Orientation="Vertical">
<TextBlock x:Name="categoriesTb"
TextAlignment="Right"
HorizontalAlignment="Center"
Text="Categories"
utu:AutoLayout.CounterAlignment="Start"
Foreground="{ThemeResource OnBackgroundBrush}" />
<TextBlock x:Name="tacTb"
TextAlignment="Right"
HorizontalAlignment="Center"
utu:AutoLayout.CounterAlignment="Start"
Foreground="{ThemeResource OnBackgroundBrush}">
TEXT AS CONTENT
</TextBlock>
<utu:AutoLayout Spacing="8"
x:Name="MyAutoLayout"
Orientation="Horizontal">
<Button Content="Change Alignment"
Click="Button_Click_2" />
<Button Content="Change Orientation"
Click="Button_Click" />
</utu:AutoLayout>
</utu:AutoLayout>
</Grid>
- When the app starts, the
TextBlock
s are aligned to the left. - I click the "Change Alignment" button, which sets the
TextBlock
s'HorizontalAlignment
toCenter
via C#—this works, and they align to the center. - I click the "Change Orientation" button, which changes
MyAutoLayout
's orientation toVertical
. - The orientation change applies successfully, but the
TextBlock
s return to the left.
Recording.2025-03-05.175150.mp4
There's a power struggle between the AutoLayout
Counter/PrimaryAlignment properties and the Horizontal/VerticalAlignments somewhere and they aren't being respected in the proper order of precedence.
Expected behavior
There shouldn't be a conflict in HorizontalAlignment
in AutoLayout
children. Questions that need answer:
- Should
HorizontalAlignment
have effect on elements inside anAutoLayout
? - Shouldn't only
utu:AutoLayout.PrimaryAlignment
andutu:AutoLayout.CounterAlignment
be used to modify elements alilgnment inside anAutoLayout
?
How to reproduce it (as minimally and precisely as possible)
Repro
hd2034.zip <<<<<<<<<<<<<<<<<<<<<<
Nuget Package:
Uno.Toolkit.WinUI
:6.4.1