diff --git a/demo/Ursa.Demo/Pages/DatePickerDemo.axaml b/demo/Ursa.Demo/Pages/DatePickerDemo.axaml
index bcf1797..0319ad6 100644
--- a/demo/Ursa.Demo/Pages/DatePickerDemo.axaml
+++ b/demo/Ursa.Demo/Pages/DatePickerDemo.axaml
@@ -8,7 +8,7 @@
-
-
+
+
diff --git a/src/Ursa.Themes.Semi/Controls/DatePicker.axaml b/src/Ursa.Themes.Semi/Controls/DatePicker.axaml
index 518c63c..6ddb92c 100644
--- a/src/Ursa.Themes.Semi/Controls/DatePicker.axaml
+++ b/src/Ursa.Themes.Semi/Controls/DatePicker.axaml
@@ -1,6 +1,7 @@
@@ -30,7 +31,7 @@
+ ColumnDefinitions="*, Auto">
@@ -83,9 +85,9 @@
@@ -95,6 +97,12 @@
+
+
+
-
diff --git a/src/Ursa/Controls/DateTimePicker/DatePicker.cs b/src/Ursa/Controls/DateTimePicker/DatePicker.cs
index eef47d9..b70c152 100644
--- a/src/Ursa/Controls/DateTimePicker/DatePicker.cs
+++ b/src/Ursa/Controls/DateTimePicker/DatePicker.cs
@@ -1,4 +1,5 @@
using System.Globalization;
+using System.Runtime.CompilerServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
@@ -116,7 +117,13 @@ public class DatePicker: DatePickerBase, IClearControl
SetCurrentValue(IsDropdownOpenProperty, true);
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void OnTextChanged(object sender, TextChangedEventArgs e)
+ {
+ SetSelectedDate(true);
+ }
+
+ private void SetSelectedDate(bool fromText = false)
{
if (string.IsNullOrEmpty(_textBox?.Text))
{
@@ -145,6 +152,15 @@ public class DatePicker: DatePickerBase, IClearControl
}
_calendar?.MarkDates(startDate: date, endDate: date);
}
+ else
+ {
+ SetCurrentValue(SelectedDateProperty, null);
+ if (!fromText)
+ {
+ _textBox?.SetValue(TextBox.TextProperty, null);
+ }
+ _calendar?.ClearSelection();
+ }
}
}
@@ -158,7 +174,14 @@ public class DatePicker: DatePickerBase, IClearControl
}
SetCurrentValue(IsDropdownOpenProperty, true);
}
-
+
+ protected override void OnLostFocus(RoutedEventArgs e)
+ {
+ base.OnLostFocus(e);
+ SetCurrentValue(IsDropdownOpenProperty, false);
+ SetSelectedDate();
+ }
+
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Escape)
@@ -186,6 +209,6 @@ public class DatePicker: DatePickerBase, IClearControl
public void Clear()
{
-
+ SetCurrentValue(SelectedDateProperty, null);
}
}
\ No newline at end of file
diff --git a/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs b/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs
index aa7ca22..bbc43df 100644
--- a/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs
+++ b/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs
@@ -6,6 +6,8 @@ using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
+using Irihi.Avalonia.Shared.Common;
+using Irihi.Avalonia.Shared.Contracts;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -16,7 +18,8 @@ namespace Ursa.Controls;
[TemplatePart(PART_EndCalendar, typeof(CalendarView))]
[TemplatePart(PART_StartTextBox, typeof(TextBox))]
[TemplatePart(PART_EndTextBox, typeof(TextBox))]
-public class DateRangePicker : DatePickerBase
+[PseudoClasses(PseudoClassName.PC_Empty)]
+public class DateRangePicker : DatePickerBase, IClearControl
{
public const string PART_Button = "PART_Button";
public const string PART_Popup = "PART_Popup";
@@ -33,19 +36,18 @@ public class DateRangePicker : DatePickerBase
AvaloniaProperty.Register(
nameof(SelectedEndDate), defaultBindingMode: BindingMode.TwoWay);
- public static readonly StyledProperty EnableMonthSyncProperty = AvaloniaProperty.Register(
- nameof(EnableMonthSync));
-
- public bool EnableMonthSync
- {
- get => GetValue(EnableMonthSyncProperty);
- set => SetValue(EnableMonthSyncProperty, value);
- }
+ public static readonly StyledProperty EnableMonthSyncProperty =
+ AvaloniaProperty.Register(
+ nameof(EnableMonthSync));
private Button? _button;
private CalendarView? _endCalendar;
private TextBox? _endTextBox;
private Popup? _popup;
+ private DateTime? _previewEnd;
+
+ private DateTime? _previewStart;
+ private bool? _start;
private CalendarView? _startCalendar;
private TextBox? _startTextBox;
@@ -57,6 +59,12 @@ public class DateRangePicker : DatePickerBase
picker.OnSelectionChanged(args));
}
+ public bool EnableMonthSync
+ {
+ get => GetValue(EnableMonthSyncProperty);
+ set => SetValue(EnableMonthSyncProperty, value);
+ }
+
public DateTime? SelectedStartDate
{
get => GetValue(SelectedStartDateProperty);
@@ -69,6 +77,12 @@ public class DateRangePicker : DatePickerBase
set => SetValue(SelectedEndDateProperty, value);
}
+ public void Clear()
+ {
+ SetCurrentValue(SelectedStartDateProperty, null);
+ SetCurrentValue(SelectedEndDateProperty, null);
+ }
+
private void OnSelectionChanged(AvaloniaPropertyChangedEventArgs args)
{
@@ -100,6 +114,7 @@ public class DateRangePicker : DatePickerBase
args.NewValue.Value.Value.ToString(DisplayFormat ?? "yyyy-MM-dd"));
}
}
+ PseudoClasses.Set(PseudoClassName.PC_Empty, SelectedStartDate is null && SelectedEndDate is null);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
@@ -109,36 +124,42 @@ public class DateRangePicker : DatePickerBase
TextBox.TextChangedEvent.RemoveHandler(OnTextChanged, _startTextBox, _endTextBox);
PointerPressedEvent.RemoveHandler(OnTextBoxPointerPressed, _startTextBox, _endTextBox);
Button.ClickEvent.RemoveHandler(OnButtonClick, _button);
+ LostFocusEvent.RemoveHandler(OnTextBoxLostFocus, _startTextBox, _endTextBox);
if (_startCalendar != null)
{
_startCalendar.DateSelected -= OnDateSelected;
_startCalendar.DatePreviewed -= OnDatePreviewed;
_startCalendar.ContextDateChanged -= OnContextDateChanged;
}
+
if (_endCalendar != null)
{
_endCalendar.DateSelected -= OnDateSelected;
_endCalendar.DatePreviewed -= OnDatePreviewed;
_endCalendar.ContextDateChanged -= OnContextDateChanged;
}
+
_button = e.NameScope.Find