diff --git a/src/Uno.Toolkit.UI/Controls/TabBar/TabBar.cs b/src/Uno.Toolkit.UI/Controls/TabBar/TabBar.cs index 5ed95ec11..5193cf862 100644 --- a/src/Uno.Toolkit.UI/Controls/TabBar/TabBar.cs +++ b/src/Uno.Toolkit.UI/Controls/TabBar/TabBar.cs @@ -195,6 +195,14 @@ private void OnLoaded(object sender, RoutedEventArgs e) UpdateOrientation(); } + internal void OnItemsPanelConnected(TabBarListPanel panel) + { + System.Diagnostics.Debug.Assert(ItemsPanelRoot != null, "ItemsPanelRoot is expected to be already set in here."); + + SynchronizeInitialSelection(); + UpdateOrientation(); + } + private void OnTabBarItemClick(object sender, RoutedEventArgs e) { if (_isSynchronizingSelection) @@ -441,7 +449,7 @@ private void RaiseSelectionChangedEvent(object? prevItem, object? nextItem) return null; } - private bool IsReady => _isLoaded && HasItems; + private bool IsReady => _isLoaded && HasItems && ItemsPanelRoot is { }; private bool HasItems => this.GetItems().Any(); } diff --git a/src/Uno.Toolkit.UI/Controls/TabBar/TabBarListPanel.cs b/src/Uno.Toolkit.UI/Controls/TabBar/TabBarListPanel.cs index b75aaf065..1cf455530 100644 --- a/src/Uno.Toolkit.UI/Controls/TabBar/TabBarListPanel.cs +++ b/src/Uno.Toolkit.UI/Controls/TabBar/TabBarListPanel.cs @@ -17,6 +17,7 @@ namespace Uno.Toolkit.UI { public partial class TabBarListPanel : Panel { + #region Orientation public Orientation Orientation { get { return (Orientation)GetValue(OrientationProperty); } @@ -28,6 +29,20 @@ public Orientation Orientation typeof(Orientation), typeof(TabBarListPanel), new PropertyMetadata(Orientation.Horizontal, (s, e) => ((TabBarListPanel)s).OnPropertyChanged(e))); + #endregion + + public TabBarListPanel() + { + this.Loaded += OnLoaded; + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + var owner = this.FindFirstParent(); + + // workaround for #1287 ItemsPanelRoot resolution timing related issue + owner?.OnItemsPanelConnected(this); + } private void OnPropertyChanged(DependencyPropertyChangedEventArgs args) {