diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootHeader.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootHeader.cs index b9fec8d79748..a2bf82ec76bf 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootHeader.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootHeader.cs @@ -200,6 +200,10 @@ public override void ViewDidLoad() UpdateSelectedIndex(); ShellSection.PropertyChanged += OnShellSectionPropertyChanged; + foreach (var shellContent in ShellSectionController.GetItems()) + { + shellContent.PropertyChanged += OnShellContentPropertyChanged; + } } protected virtual Type GetCellType() @@ -217,6 +221,10 @@ protected override void Dispose(bool disposing) ((IShellController)_shellContext.Shell).RemoveAppearanceObserver(this); ShellSectionController.ItemsCollectionChanged -= OnShellSectionItemsChanged; ShellSection.PropertyChanged -= OnShellSectionPropertyChanged; + foreach (var shellContent in ShellSectionController.GetItems()) + { + shellContent.PropertyChanged -= OnShellContentPropertyChanged; + } ShellSection = null; _bar.RemoveFromSuperview(); @@ -279,9 +287,53 @@ protected virtual void UpdateSelectedIndex(bool animated = false) void OnShellSectionItemsChanged(object sender, NotifyCollectionChangedEventArgs e) { + HandleEventsOnItemsChange(e); ReloadData(); } + void HandleEventsOnItemsChange(NotifyCollectionChangedEventArgs e) + { + if (e.OldItems != null) + { + foreach (ShellContent item in e.OldItems) + { + item.PropertyChanged -= OnShellContentPropertyChanged; + } + } + + if (e.NewItems != null) + { + foreach (ShellContent item in e.NewItems) + { + item.PropertyChanged += OnShellContentPropertyChanged; + } + } + } + + void OnShellContentPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(ShellContent.Title)) + { + if (sender is ShellContent shellContent) + { + int index = ShellSectionController.GetItems().IndexOf(shellContent); + if (index >= 0) + { + UpdateHeaderTitle(index, shellContent); + } + } + } + } + + void UpdateHeaderTitle(int index, ShellContent shellContent) + { + if (CollectionView.CellForItem(NSIndexPath.FromItemSection(index, 0)) is ShellSectionHeaderCell cell) + { + cell.Label.Text = shellContent.Title; + CollectionView.CollectionViewLayout.InvalidateLayout(); + } + } + void ReloadData() { if (_isDisposed) diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue26049.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue26049.xaml new file mode 100644 index 000000000000..5dd43fa4d37b --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue26049.xaml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + +