feat: make panel format nullable. Update display text on display format change.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -130,12 +130,12 @@ public class TimePickerPresenter : TemplatedControl
|
||||
private void OnPanelFormatChanged(AvaloniaPropertyChangedEventArgs<string> args)
|
||||
{
|
||||
var format = args.NewValue.Value;
|
||||
|
||||
UpdatePanelLayout(format);
|
||||
}
|
||||
|
||||
private void UpdatePanelLayout(string panelFormat)
|
||||
private void UpdatePanelLayout(string? panelFormat)
|
||||
{
|
||||
if (panelFormat is null) return;
|
||||
var parts = panelFormat.Split(new[] { ' ', '-', ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var panels = new List<Control?>();
|
||||
foreach (var part in parts)
|
||||
|
||||
Reference in New Issue
Block a user