-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Windows] Fix DatePicker CharacterSpacing Property Not Working #30495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
138797f
397a2e8
0e635eb
90f364e
cf6e0e0
1e228a7
f834b1e
3c4afa5
67ccbd9
ac7f2e4
a636e4c
d784d40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
}; | ||
} | ||
} | ||
} |
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(); | ||
} | ||
|
||
[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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] If
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
static void ApplyCharacterSpacingToTextBlocks(CalendarDatePicker platformDatePicker, double characterSpacing) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
var characterSpacingEm = characterSpacing.ToEm(); | ||||||||||||||||||||||||||
var dateTextBlock = platformDatePicker.GetDescendantByName<TextBlock>("DateText"); | ||||||||||||||||||||||||||
Comment on lines
+56
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||
if (dateTextBlock is not null) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
dateTextBlock.CharacterSpacing = characterSpacingEm; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
public static void UpdateFont(this CalendarDatePicker platformDatePicker, IDatePicker datePicker, IFontManager fontManager) => | ||||||||||||||||||||||||||
platformDatePicker.UpdateFont(datePicker.Font, fontManager); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Snapshots already available in the latest build.
There was a problem hiding this comment.
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