Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.Element>
~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void
Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Element>
~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void
Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, TArgs>(TSender sender, string message, TArgs args) -> void
*REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send<TSender>(TSender sender, string message) -> void
*REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Subscribe<TSender, TArgs>(object subscriber, string message, System.Action<TSender, TArgs> callback, TSender source = null) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Element>
~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void
Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness
Expand Down
3 changes: 3 additions & 0 deletions src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.Element>
~Microsoft.Maui.Controls.ContentPresenter.LowerChild(Microsoft.Maui.Controls.View view) -> void
Microsoft.Maui.Controls.ContentPresenter.Padding.get -> Microsoft.Maui.Thickness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 38 additions & 18 deletions src/Controls/src/Core/TitleBar/TitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,84 +71,89 @@ public partial class TitleBar : TemplatedView, ITitleBar, ISafeAreaView
public static readonly BindableProperty ForegroundColorProperty = BindableProperty.Create(nameof(ForegroundColor),
typeof(Color), typeof(TitleBar));

/// <summary>Bindable property for <see cref="TitleFontAttributes"/>.</summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use bold by default? Using None maintain backward compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I have changed the default value to FontAttributes.None to maintain backward compatibility.

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();
}
}
Expand Down Expand Up @@ -236,6 +241,16 @@ public Color ForegroundColor
set { SetValue(ForegroundColorProperty, value); }
}

/// <summary>
/// Gets or sets the <see cref="FontAttributes"/> applied to the title text.
/// Defaults to <see cref="FontAttributes.None"/>.
/// </summary>
public FontAttributes TitleFontAttributes
{
get => (FontAttributes)GetValue(TitleFontAttributesProperty);
set => SetValue(TitleFontAttributesProperty, value);
}

/// <inheritdoc/>
public IList<IView> PassthroughElements { get; private set; }

Expand Down Expand Up @@ -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()
Expand Down
77 changes: 77 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24627.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading