From bce2532f13957d8501083f850cca5eb7d8f3f634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agn=C3=A8s=20ZITTE?= <16295702+agneszitte-nventive@users.noreply.github.com> Date: Fri, 27 Jan 2023 15:28:09 -0400 Subject: [PATCH] fix(AutoLayout): Making sure the AutoLayout is correctly loaded before updating the layout (#458) (#462) --- src/Uno.Toolkit.UI/Controls/AutoLayout/AutoLayout.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Uno.Toolkit.UI/Controls/AutoLayout/AutoLayout.cs b/src/Uno.Toolkit.UI/Controls/AutoLayout/AutoLayout.cs index e6331e83b..de7eff441 100644 --- a/src/Uno.Toolkit.UI/Controls/AutoLayout/AutoLayout.cs +++ b/src/Uno.Toolkit.UI/Controls/AutoLayout/AutoLayout.cs @@ -27,6 +27,8 @@ public AutoLayout() DefaultStyleKey = typeof(AutoLayout); Children = new AutoLayoutChildren(); + Loaded += OnLoaded; + this.RegisterDisposablePropertyChangedCallback(HorizontalAlignmentProperty, (snd, e) => UpdateAutoLayout()); this.RegisterDisposablePropertyChangedCallback(VerticalAlignmentProperty, (snd, e) => UpdateAutoLayout()); this.RegisterDisposablePropertyChangedCallback(PaddingProperty, (snd, e) => UpdateAutoLayout()); @@ -41,6 +43,11 @@ protected override void OnApplyTemplate() UpdateAutoLayout(); } + private static void OnLoaded(object sender, RoutedEventArgs e) + { + (sender as AutoLayout)?.UpdateAutoLayout(); + } + public static readonly DependencyProperty IsReverseZIndexProperty = DependencyProperty.Register( "IsReverseZIndex", typeof(bool), typeof(AutoLayout), new PropertyMetadata(default(bool), propertyChangedCallback: UpdateCallback));