Skip to content
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

Prevent DatePicker and TimePicker fields from being overriden #8227

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions src/Avalonia.Controls/DateTimePickers/DatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ private void SetSelectedDateText()
else
{
PseudoClasses.Set(":hasnodate", true);
_monthText!.Text = "month";
_yearText!.Text = "year";
_dayText!.Text = "day";
_monthText!.Text ??= "month";
_yearText!.Text ??= "year";
_dayText!.Text ??= "day";
Copy link
Contributor

Choose a reason for hiding this comment

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

This will fail if you clear the selected date (or time) after having it previously set since the TextBlock text won't be null. WinUI probably has localized strings here to prevent English only.
TextBlock.Text is also a DirectProperty, not a StyledProperty, so there's a chance the Style lookup in the OP will fail, and may not even work here to allow custom strings for :hasnodate (or :hasnotime)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, property localization for internal avalonia strings is something that we must have. It needs a proper design though.

}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/DateTimePickers/TimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ private void SetSelectedTimeText()
}
else
{
_hourText.Text = "hour";
_minuteText.Text = "minute";
_hourText.Text ??= "hour";
_minuteText.Text ??= "minute";
PseudoClasses.Set(":hasnotime", true);

_periodText.Text = DateTime.Now.Hour >= 12 ? CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator :
Expand Down