Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoLayout children have conflicting HorizontalAlignment behavior #1361

Open
erikvilima opened this issue Mar 5, 2025 · 1 comment
Open
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification.

Comments

@erikvilima
Copy link
Contributor

erikvilima commented Mar 5, 2025

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>
  1. When the app starts, the TextBlocks are aligned to the left.
  2. I click the "Change Alignment" button, which sets the TextBlocks' HorizontalAlignment to Center via C#—this works, and they align to the center.
  3. I click the "Change Orientation" button, which changes MyAutoLayout's orientation to Vertical.
  4. The orientation change applies successfully, but the TextBlocks 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:

  1. Should HorizontalAlignment have effect on elements inside an AutoLayout?
  2. Shouldn't only utu:AutoLayout.PrimaryAlignment and utu:AutoLayout.CounterAlignment be used to modify elements alilgnment inside an AutoLayout?

How to reproduce it (as minimally and precisely as possible)

Repro

hd2034.zip <<<<<<<<<<<<<<<<<<<<<<

Nuget Package:
Uno.Toolkit.WinUI:6.4.1

@erikvilima erikvilima added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification. labels Mar 5, 2025
@kazo0
Copy link
Contributor

kazo0 commented Mar 6, 2025

fyi AutoLayout master @carldebilly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification.
Projects
None yet
Development

No branches or pull requests

2 participants