feat: make panel format nullable. Update display text on display format change.

This commit is contained in:
rabbitism
2024-05-16 22:48:46 +08:00
parent 18e5996f73
commit 2ccea8fe1e
2 changed files with 12 additions and 2 deletions

View File

@@ -39,6 +39,16 @@ public class TimePicker : TimePickerBase, IClearControl
{
SelectedTimeProperty.Changed.AddClassHandler<TimePicker, TimeSpan?>((picker, args) =>
picker.OnSelectionChanged(args));
DisplayFormatProperty.Changed.AddClassHandler<TimePicker, string?>((picker, args) => picker.OnDisplayFormatChanged(args));
}
private void OnDisplayFormatChanged(AvaloniaPropertyChangedEventArgs<string?> args)
{
if (_textBox is null) return;
var time = SelectedTime;
var date = new DateTime( 1, 1, 1, time.Value.Hours, time.Value.Minutes, time.Value.Seconds);
var text = date.ToString(DisplayFormat);
_textBox.Text = text;
}
public string? Watermark