diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Pivot.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Pivot.cs index 8d1ab8580f01..e82836c2a9b9 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Pivot.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Pivot.cs @@ -11,6 +11,7 @@ using FluentAssertions.Execution; using static Private.Infrastructure.TestServices; using Uno.UI.Extensions; +using Windows.UI.Xaml.Controls.Primitives; namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls { @@ -71,6 +72,26 @@ public async Task Check_Binding() items[1].Content.Should().Be(tbs2.ElementAt(0).Text); } + [TestMethod] + [RunsOnUIThread] + public async Task Check_Changing_Header_Affects_UI() + { + var pivotItem = new PivotItem { Header = "Initial text" }; + var SUT = new Pivot + { + Items = { pivotItem }, + }; + + WindowHelper.WindowContent = SUT; + await WindowHelper.WaitForIdle(); + + var pivotHeaderPanel = (PivotHeaderPanel)SUT.GetTemplateChild("StaticHeader"); + var headerItem = (PivotHeaderItem)pivotHeaderPanel.Children.Single(); + headerItem.Content.Should().Be("Initial text"); + pivotItem.Header = "New text"; + headerItem.Content.Should().Be("New text"); + } + private class MyContext { public MyContext() diff --git a/src/Uno.UI/UI/Xaml/Controls/Pivot/Pivot.cs b/src/Uno.UI/UI/Xaml/Controls/Pivot/Pivot.cs index ff406149efed..a033f5a33bf5 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Pivot/Pivot.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Pivot/Pivot.cs @@ -165,6 +165,7 @@ private void SynchronizeItems() if (item is PivotItem pivotItem) { + pivotItem.PivotHeaderItem = headerItem; headerItem.Content = pivotItem.Header; } else diff --git a/src/Uno.UI/UI/Xaml/Controls/Pivot/PivotItem.cs b/src/Uno.UI/UI/Xaml/Controls/Pivot/PivotItem.cs index d317e7919254..3456d7e8c427 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Pivot/PivotItem.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Pivot/PivotItem.cs @@ -3,14 +3,15 @@ using System.Drawing; using System.Text; using Uno.UI; +using Windows.UI.Xaml.Controls.Primitives; #if XAMARIN_ANDROID using Android.Views; #endif namespace Windows.UI.Xaml.Controls { - public partial class PivotItem : ContentControl - { + public partial class PivotItem : ContentControl + { public PivotItem() { this.HorizontalAlignment = HorizontalAlignment.Stretch; @@ -27,6 +28,8 @@ public PivotItem(string header) : this() Header = header; } + internal PivotHeaderItem PivotHeaderItem { get; set; } + protected override bool CanCreateTemplateWithoutParent => true; public object Header @@ -35,8 +38,17 @@ public object Header set { this.SetValue(HeaderProperty, value); } } - public static DependencyProperty HeaderProperty { get ; } = - DependencyProperty.Register("Header", typeof(object), typeof(PivotItem), new FrameworkPropertyMetadata(null)); + public static DependencyProperty HeaderProperty { get; } = + DependencyProperty.Register("Header", typeof(object), typeof(PivotItem), new FrameworkPropertyMetadata(null, propertyChangedCallback: OnHeaderChanged)); + + private static void OnHeaderChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) + { + if (dependencyObject is PivotItem item && item.PivotHeaderItem != null) + { + item.PivotHeaderItem.Content = args.NewValue; + + } + } #if XAMARIN_ANDROID // This allows the PivotItem to fill the whole available space.