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

[Fix] Issue when the time is cleared if a date is selected #2837

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;

/// <summary>
/// Represents a control that allows the user to select a date and a time.
Expand Down Expand Up @@ -156,7 +157,7 @@ protected override void ApplyBindings()
_calendar.SetBinding(Calendar.FirstDayOfWeekProperty, GetBinding(FirstDayOfWeekProperty));
_calendar.SetBinding(Calendar.IsTodayHighlightedProperty, GetBinding(IsTodayHighlightedProperty));
_calendar.SetBinding(FlowDirectionProperty, GetBinding(FlowDirectionProperty));
_calendar.SetBinding(Calendar.SelectedDateProperty, GetBinding(SelectedDateProperty));
_calendar.SelectedDatesChanged += OnCalendarSelectedDateChanged;
}
}

Expand All @@ -177,6 +178,15 @@ protected override string GetValueForTextBox()
return valueForTextBox;
}

protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
base.OnPreviewMouseUp(e);
if (Mouse.Captured is CalendarItem)
{
Mouse.Capture(null);
}
}

protected override void OnRangeBaseValueChanged(object sender, SelectionChangedEventArgs e)
{
base.OnRangeBaseValueChanged(sender, e);
Expand Down Expand Up @@ -210,6 +220,19 @@ protected override void WriteValueToTextBox()
}
}

private void OnCalendarSelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
var dt = (DateTime)e.AddedItems[0];

var timeOfDay = SelectedDate.GetValueOrDefault().TimeOfDay;

dt += timeOfDay;
SelectedDate = dt;
}
}

private static object CoerceOrientation(DependencyObject d, object basevalue)
{
if (((DateTimePicker)d).IsClockVisible)
Expand Down