Skip to content

Commit

Permalink
Fix issue( #105
Browse files Browse the repository at this point in the history
Fix issue( #105
  • Loading branch information
yanjinhuagood committed Aug 19, 2024
1 parent c0dae74 commit dac14f7
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/WPFDevelopers.Shared/Controls/TimePicker/TimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_textBox = GetTemplateChild(EditableTextBoxTemplateName) as TextBox;
if (_textBox != null)
_textBox.TextChanged += TextBox_TextChanged;
_timeSelector = GetTemplateChild(TimeSelectorTemplateName) as TimeSelector;
if (_timeSelector != null)
{
Expand All @@ -111,12 +113,25 @@ public override void OnApplyTemplate()
}
}

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (_textBox != null)
{
_timeSelector.SelectedTimeChanged -= TimeSelector_SelectedTimeChanged;
if (DateTime.TryParse(_textBox.Text, out var dateTime))
{
if (SelectedTime.HasValue && dateTime.ToString(SelectedTimeFormat) == SelectedTime.Value.ToString(SelectedTimeFormat)) return;
SelectedTime = dateTime;
}
else
SelectedTime = null;
_timeSelector.SelectedTimeChanged += TimeSelector_SelectedTimeChanged;
}
}
private void Popup_Opened(object sender, EventArgs e)
{
if (_timeSelector != null)
{
_timeSelector.SetTime();
}
}

private void TimeSelector_SelectedTimeChanged(object sender, RoutedPropertyChangedEventArgs<DateTime?> e)
Expand Down

0 comments on commit dac14f7

Please sign in to comment.