diff --git a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt index 32a21e9da66a..399db284ceea 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -30,6 +30,9 @@ Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.get -> Microsoft.Maui.SafeArea Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.set -> void Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.get -> bool Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.set -> void +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void +static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! ~Microsoft.Maui.Controls.ContentPresenter.Children.get -> System.Collections.Generic.IReadOnlyList ~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness diff --git a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 869def3ea434..b262a887e2fd 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -37,6 +37,9 @@ Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.set -> void ~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness Microsoft.Maui.Controls.ContentPresenter.Padding.set -> void +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void +static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! ~Microsoft.Maui.Controls.ContentPresenter.RaiseChild(Microsoft.Maui.Controls.View view) -> void Microsoft.Maui.Controls.ContentPresenter.UpdateChildrenLayout() -> void Microsoft.Maui.Controls.ContentView.SafeAreaEdges.get -> Microsoft.Maui.SafeAreaEdges diff --git a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 869def3ea434..4bb7e3e164e2 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -33,6 +33,9 @@ Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.get -> Microsoft.Maui.SafeArea Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.set -> void Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.get -> bool Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.set -> void +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void +static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! ~Microsoft.Maui.Controls.ContentPresenter.Children.get -> System.Collections.Generic.IReadOnlyList ~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness diff --git a/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt index 239b55f31a2b..928d058e3926 100644 --- a/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt @@ -34,6 +34,9 @@ Microsoft.Maui.Controls.ILineHeightElement.OnLineHeightChanged(double oldValue, *REMOVED*Microsoft.Maui.Controls.IMessagingCenter Microsoft.Maui.Controls.SearchHandler.HideSoftInputAsync() -> void Microsoft.Maui.Controls.SearchHandler.ShowSoftInputAsync() -> void +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void +static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Subscribe(object subscriber, string message, System.Action callback, TSender source = null) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt index b2acc61e5c3f..1cebf28c5ad0 100644 --- a/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt @@ -30,6 +30,9 @@ Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.get -> Microsoft.Maui.SafeArea Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.set -> void Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.get -> bool Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.set -> void +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void +static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! ~Microsoft.Maui.Controls.ContentPresenter.Children.get -> System.Collections.Generic.IReadOnlyList ~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness diff --git a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt index 83dab46327ec..c00cfb1f397d 100644 --- a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt @@ -30,6 +30,9 @@ Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.get -> Microsoft.Maui.SafeArea Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.set -> void Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.get -> bool Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.set -> void +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void +static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! ~Microsoft.Maui.Controls.ContentPresenter.Children.get -> System.Collections.Generic.IReadOnlyList ~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness diff --git a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt index 1b1d6e3c4a4a..a392c52a558e 100644 --- a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt @@ -30,6 +30,9 @@ Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.get -> Microsoft.Maui.SafeArea Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.set -> void Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.get -> bool Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.set -> void +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes +Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void +static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! override Microsoft.Maui.Controls.CheckBox.IsEnabledCore.get -> bool ~Microsoft.Maui.Controls.CheckBox.Command.get -> System.Windows.Input.ICommand ~Microsoft.Maui.Controls.CheckBox.Command.set -> void diff --git a/src/Controls/src/Core/TitleBar/TitleBar.cs b/src/Controls/src/Core/TitleBar/TitleBar.cs index 37eb60c04266..3ede9ff96981 100644 --- a/src/Controls/src/Core/TitleBar/TitleBar.cs +++ b/src/Controls/src/Core/TitleBar/TitleBar.cs @@ -71,84 +71,89 @@ public partial class TitleBar : TemplatedView, ITitleBar, ISafeAreaView public static readonly BindableProperty ForegroundColorProperty = BindableProperty.Create(nameof(ForegroundColor), typeof(Color), typeof(TitleBar)); + /// Bindable property for . + public static readonly BindableProperty TitleFontAttributesProperty = + BindableProperty.Create(nameof(TitleFontAttributes), typeof(FontAttributes), + typeof(TitleBar), FontAttributes.None); + static void OnLeadingChanged(BindableObject bindable, object oldValue, object newValue) { - var titlebar = (TitleBar)bindable; + var titleBar = (TitleBar)bindable; if (newValue is null) { - titlebar.ApplyVisibleState(LeadingHiddenState); + titleBar.ApplyVisibleState(LeadingHiddenState); } else { - titlebar.ApplyVisibleState(LeadingVisibleState); + titleBar.ApplyVisibleState(LeadingVisibleState); (newValue as Layout)?.IgnoreLayoutSafeArea(); } } static void OnIconChanged(BindableObject bindable, object oldValue, object newValue) { - var titlebar = (TitleBar)bindable; + var titleBar = (TitleBar)bindable; var imageSource = newValue as ImageSource; if (imageSource is null || imageSource.IsEmpty) { - titlebar.ApplyVisibleState(IconHiddenState); + titleBar.ApplyVisibleState(IconHiddenState); } else { - titlebar.ApplyVisibleState(IconVisibleState); + titleBar.ApplyVisibleState(IconVisibleState); } } static void OnTitleChanged(BindableObject bindable, object oldValue, object newValue) { - var titlebar = (TitleBar)bindable; + var titleBar = (TitleBar)bindable; if (newValue is null) { - titlebar.ApplyVisibleState(TitleHiddenState); + titleBar.ApplyVisibleState(TitleHiddenState); } else { - titlebar.ApplyVisibleState(TitleVisibleState); + titleBar.ApplyVisibleState(TitleVisibleState); } } static void OnSubtitleChanged(BindableObject bindable, object oldValue, object newValue) { - var titlebar = (TitleBar)bindable; + var titleBar = (TitleBar)bindable; if (newValue is null) { - titlebar.ApplyVisibleState(SubtitleHiddenState); + titleBar.ApplyVisibleState(SubtitleHiddenState); } else { - titlebar.ApplyVisibleState(SubtitleVisibleState); + titleBar.ApplyVisibleState(SubtitleVisibleState); } } static void OnContentChanged(BindableObject bindable, object oldValue, object newValue) { - var titlebar = (TitleBar)bindable; + var titleBar = (TitleBar)bindable; if (newValue is null) { - titlebar.ApplyVisibleState(ContentHiddenState); + titleBar.ApplyVisibleState(ContentHiddenState); } else { - titlebar.ApplyVisibleState(ContentVisibleState); + titleBar.ApplyVisibleState(ContentVisibleState); (newValue as Layout)?.IgnoreLayoutSafeArea(); } } static void OnTrailingContentChanged(BindableObject bindable, object oldValue, object newValue) { - var titlebar = (TitleBar)bindable; + var titleBar = (TitleBar)bindable; if (newValue is null) { - titlebar.ApplyVisibleState(TrailingHiddenState); + titleBar.ApplyVisibleState(TrailingHiddenState); } else { - titlebar.ApplyVisibleState(TrailingVisibleState); + titleBar.ApplyVisibleState(TrailingVisibleState); (newValue as Layout)?.IgnoreLayoutSafeArea(); } } @@ -236,6 +241,16 @@ public Color ForegroundColor set { SetValue(ForegroundColorProperty, value); } } + /// + /// Gets or sets the applied to the title text. + /// Defaults to . + /// + public FontAttributes TitleFontAttributes + { + get => (FontAttributes)GetValue(TitleFontAttributesProperty); + set => SetValue(TitleFontAttributesProperty, value); + } + /// public IList PassthroughElements { get; private set; } @@ -451,6 +466,11 @@ static View BuildDefaultTemplate() static (TitleBar tb) => tb.ForegroundColor, source: RelativeBindingSource.TemplatedParent); + titleLabel.SetBinding( + Label.FontAttributesProperty, + static (TitleBar tb) => tb.TitleFontAttributes, + source: RelativeBindingSource.TemplatedParent); + var activeVisualState = new VisualState() { Name = TitleBarActiveState }; activeVisualState.Setters.Add( new Setter() diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24627.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24627.cs new file mode 100644 index 000000000000..4eec45787704 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24627.cs @@ -0,0 +1,77 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 24627, "[Windows] TitleBar Title FontAttributes", PlatformAffected.UWP)] +public class Issue24627 : ContentPage +{ + TitleBar customTitleBar; + + public Issue24627() + { + customTitleBar = new TitleBar + { + Title = "MauiApp1", + Subtitle = "Welcome to .NET MAUI", + TitleFontAttributes = FontAttributes.Bold, + HeightRequest = 32 + }; + + var label = new Label + { + Text = "Welcome to .NET MAUI", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + }; + + var button = new Button + { + Text = "Set Title FontAttributes to None", + AutomationId = "ChangeFAButton", + Command = new Command(() => + { + customTitleBar.TitleFontAttributes = FontAttributes.None; + }), + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + + var italicButton = new Button + { + Text = "Set Title FontAttributes to Italic", + AutomationId = "ItalicButton", + Command = new Command(() => + { + customTitleBar.TitleFontAttributes = FontAttributes.Italic; + }), + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + + var verticalStack = new VerticalStackLayout + { + Children = + { + label, + button, + italicButton + }, + Spacing = 25, + Padding = new Thickness(30, 0), + VerticalOptions = LayoutOptions.Center + }; + + Content = verticalStack; + } + + protected override void OnAppearing() + { + base.OnAppearing(); + if (Window is not null) + { + Window.TitleBar = customTitleBar; + } + else if (Shell.Current?.Window is not null) + { + Shell.Current.Window.TitleBar = customTitleBar; + } + } +} diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ChangeTitleBarTitleFontAttributesToItalic.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ChangeTitleBarTitleFontAttributesToItalic.png new file mode 100644 index 000000000000..e64e33805a8b Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ChangeTitleBarTitleFontAttributesToItalic.png differ diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ChangeTitleBarTitleFontAttributesToNone.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ChangeTitleBarTitleFontAttributesToNone.png new file mode 100644 index 000000000000..a9ee36a7e280 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ChangeTitleBarTitleFontAttributesToNone.png differ diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTitleBarTitleFontAttributesBold.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTitleBarTitleFontAttributesBold.png new file mode 100644 index 000000000000..25c2b5bf3624 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTitleBarTitleFontAttributesBold.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24627.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24627.cs new file mode 100644 index 000000000000..d4005377ba58 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24627.cs @@ -0,0 +1,42 @@ +#if WINDOWS || MACCATALYST // TitleBar is only supported on Windows and MacCatalyst +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue24627 : _IssuesUITest +{ + public override string Issue => "[Windows] TitleBar Title FontAttributes"; + + public Issue24627(TestDevice device) + : base(device) + { } + + [Test, Order(1)] + [Category(UITestCategories.TitleView)] + public void VerifyTitleBarTitleFontAttributesBold() + { + App.WaitForElement("ChangeFAButton"); + VerifyScreenshot(includeTitleBar: true); + } + + [Test, Order(2)] + [Category(UITestCategories.TitleView)] + public void ChangeTitleBarTitleFontAttributesToNone() + { + App.WaitForElement("ChangeFAButton"); + App.Tap("ChangeFAButton"); + VerifyScreenshot(includeTitleBar: true); + } + + [Test, Order(3)] + [Category(UITestCategories.TitleView)] + public void ChangeTitleBarTitleFontAttributesToItalic() + { + App.WaitForElement("ItalicButton"); + App.Tap("ItalicButton"); + VerifyScreenshot(includeTitleBar: true); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ChangeTitleBarTitleFontAttributesToItalic.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ChangeTitleBarTitleFontAttributesToItalic.png new file mode 100644 index 000000000000..293e1ed57d92 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ChangeTitleBarTitleFontAttributesToItalic.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ChangeTitleBarTitleFontAttributesToNone.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ChangeTitleBarTitleFontAttributesToNone.png new file mode 100644 index 000000000000..19123044e423 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ChangeTitleBarTitleFontAttributesToNone.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTitleBarTitleFontAttributesBold.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTitleBarTitleFontAttributesBold.png new file mode 100644 index 000000000000..848a24a33084 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTitleBarTitleFontAttributesBold.png differ