Skip to content
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.
64 changes: 64 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue30066.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.Maui.Controls;
using System;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, "30066", "DatePicker CharacterSpacing Property Not Working on Windows", PlatformAffected.UWP)]
public class Issue30066 : TestShell
{
protected override void Init()
{
var shellContent = new ShellContent
{
Title = "DatePicker CharacterSpacing Test",
Content = new Issue30066ContentPage() { Title = "DatePicker CharacterSpacing Test" }
};

Items.Add(shellContent);
}

class Issue30066ContentPage : ContentPage
{
public Issue30066ContentPage()
{
var datePicker = new DatePicker
{
Date = new DateTime(2025, 7, 9),
CharacterSpacing = 10,
Format = "M/d/yyyy",
AutomationId = "TestDatePicker",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
};

var label = new Label
{
Text = "The DatePicker above should have character spacing of 10 applied to its text.",
HorizontalOptions = LayoutOptions.Center,
Margin = new Thickness(20),
HorizontalTextAlignment = TextAlignment.Center
};

var button = new Button
{
Text = "Change Character Spacing to 20",
AutomationId = "ChangeSpacingButton",
HorizontalOptions = LayoutOptions.Center,
Margin = new Thickness(0, 20)
};

button.Clicked += (s, e) =>
{
datePicker.CharacterSpacing = datePicker.CharacterSpacing == 10 ? 20 : 10;
button.Text = $"Change Character Spacing to {(datePicker.CharacterSpacing == 10 ? 20 : 10)}";
};

Content = new StackLayout
{
Children = { datePicker, label, button },
Spacing = 20,
Margin = new Thickness(20)
};
}
}
}
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,40 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue30066 : _IssuesUITest
{
public Issue30066(TestDevice device)
: base(device)
{
}

public override string Issue => "DatePicker CharacterSpacing Property Not Working on Windows";

[Test, Order(1)]
[Category(UITestCategories.DatePicker)]
public void DatePickerCharacterSpacingShouldApply()
{
App.WaitForElement("TestDatePicker");

// Take a screenshot to verify character spacing is applied
// On Windows, the DatePicker text should show increased character spacing
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Running a build, pending snapshots on Windows.

Copy link
Contributor

Choose a reason for hiding this comment

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

image
Snapshots already available in the latest build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz , Pending snapshot has been added

}

[Test, Order(2)]
[Category(UITestCategories.DatePicker)]
public void DatePickerCharacterSpacingCanChange()
{
App.WaitForElement("TestDatePicker");
App.WaitForElement("ChangeSpacingButton");

// Change the character spacing by clicking the button
App.Tap("ChangeSpacingButton");

// Take a screenshot to verify the character spacing changed
VerifyScreenshot();
}
}
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion src/Core/src/Platform/Windows/DatePickerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,31 @@ public static void UpdateMaximumDate(this CalendarDatePicker platformDatePicker,

public static void UpdateCharacterSpacing(this CalendarDatePicker platformDatePicker, IDatePicker datePicker)
{
platformDatePicker.CharacterSpacing = datePicker.CharacterSpacing.ToEm();
// Store the character spacing value to apply it when ready
var characterSpacing = datePicker.CharacterSpacing;

// Apply immediately if loaded, otherwise wait for load
if (platformDatePicker.IsLoaded)
{
ApplyCharacterSpacingToTextBlocks(platformDatePicker, characterSpacing);
}
else
{
// Wait for the control to load, then apply character spacing
platformDatePicker.OnLoaded(() => ApplyCharacterSpacingToTextBlocks(platformDatePicker, characterSpacing));
Comment on lines +51 to +52
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

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

[nitpick] If UpdateCharacterSpacing is called multiple times before load, this may register multiple callbacks. Consider ensuring the callback runs only once or unsubscribes after first execution to prevent redundant invocations.

Suggested change
// Wait for the control to load, then apply character spacing
platformDatePicker.OnLoaded(() => ApplyCharacterSpacingToTextBlocks(platformDatePicker, characterSpacing));
// Ensure the callback is registered only once
if (!platformDatePicker.HasCharacterSpacingCallback)
{
platformDatePicker.HasCharacterSpacingCallback = true;
platformDatePicker.OnLoaded(() =>
{
ApplyCharacterSpacingToTextBlocks(platformDatePicker, characterSpacing);
platformDatePicker.HasCharacterSpacingCallback = false; // Reset the flag
});
}

Copilot uses AI. Check for mistakes.

}
}

static void ApplyCharacterSpacingToTextBlocks(CalendarDatePicker platformDatePicker, double characterSpacing)
{
var characterSpacingEm = characterSpacing.ToEm();
var dateTextBlock = platformDatePicker.GetDescendantByName<TextBlock>("DateText");
Comment on lines +56 to +59
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting the magic string "DateText" into a constant or validating it against the control template to reduce the risk of mismatches if the template changes.

Suggested change
static void ApplyCharacterSpacingToTextBlocks(CalendarDatePicker platformDatePicker, double characterSpacing)
{
var characterSpacingEm = characterSpacing.ToEm();
var dateTextBlock = platformDatePicker.GetDescendantByName<TextBlock>("DateText");
const string DateTextBlockName = "DateText";
static void ApplyCharacterSpacingToTextBlocks(CalendarDatePicker platformDatePicker, double characterSpacing)
{
var characterSpacingEm = characterSpacing.ToEm();
var dateTextBlock = platformDatePicker.GetDescendantByName<TextBlock>(DateTextBlockName);

Copilot uses AI. Check for mistakes.

if (dateTextBlock is not null)
{
dateTextBlock.CharacterSpacing = characterSpacingEm;
}
}

public static void UpdateFont(this CalendarDatePicker platformDatePicker, IDatePicker datePicker, IFontManager fontManager) =>
platformDatePicker.UpdateFont(datePicker.Font, fontManager);

Expand Down