-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Prevent DatePicker and TimePicker fields from being overriden #8227
Conversation
_dayText!.Text = "day"; | ||
_monthText!.Text ??= "month"; | ||
_yearText!.Text ??= "year"; | ||
_dayText!.Text ??= "day"; |
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.
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
)
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.
Yes, property localization for internal avalonia strings is something that we must have. It needs a proper design though.
Note, that setters to a direct properties won't be allowed in the future. Still you can create edit this field directly without styles with some code. See #7982 . Although TextBlock.Text specifically might be styleable in the future. |
@maxkatz6 could you elaborate on that? How is it currently possible to change the value of the "month" column without styling? |
@CollinAlpert sure:
|
But unfortunately, it won't work if value will be null again. So it needs to be re-refreshed with a hack...: private static void EnsureLocalization(TimePicker picker, string tempaltePartName, string value)
{
picker.TemplateApplied += (s, a) =>
{
var textBlock = a.NameScope.Find<TextBlock>(tempaltePartName);
textBlock.Text = value;
textBlock.PropertyChanged += (s, a) =>
{
if (a.Property == TextBlock.TextProperty
&& picker.SelectedTime is null)
{
textBlock.Text = value;
}
};
};
} and from ctor:
|
@maxkatz6 thanks. Although this implies a code-behind. Any way using MVVM? |
@CollinAlpert that's purely View logic, so should work with MVVM as it is. Unless you want to read localized values from the ViewModel, but in this case I don't understand how styles would solve same problem. |
What does the pull request do?
The text displayed for a
DatePicker
orTimePicker
which has no value set is hardcoded. This PR only sets the respectiveTextBlock
's text to the hardcoded value if another value has not yet been supplied (i.e. through styling).What is the current behavior?
Currently any text set through styling gets overwritten.
What is the updated/expected behavior with this PR?
Adding the following style:
This should cause an unset
DatePicker
to display the text "Monat" (German for "month") in the month's column.