This commit is contained in:
NaBian committed 2020-09-26 14:11:20 +08:00
1 parent f6502e37b1
commit 4b44ec56b5
8 files changed
+430 -136

No files matched your search

@@ -4,7 +4,9 @@ using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using HandyControl.Data;
using HandyControl.Interactivity;
@@ -268,6 +270,46 @@ namespace HandyControl.Controls
set => SetValue(ShowClearButtonProperty, ValueBoxes.BooleanBox(value));
}
public static readonly DependencyProperty SelectionBrushProperty =
TextBoxBase.SelectionBrushProperty.AddOwner(typeof(DateTimePicker));
public Brush SelectionBrush
{
get => (Brush)GetValue(SelectionBrushProperty);
set => SetValue(SelectionBrushProperty, value);
}
#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
public static readonly DependencyProperty SelectionTextBrushProperty =
TextBoxBase.SelectionTextBrushProperty.AddOwner(typeof(DateTimePicker));
public Brush SelectionTextBrush
{
get => (Brush)GetValue(SelectionTextBrushProperty);
set => SetValue(SelectionTextBrushProperty, value);
}
#endif
public static readonly DependencyProperty SelectionOpacityProperty =
TextBoxBase.SelectionOpacityProperty.AddOwner(typeof(DateTimePicker));
public double SelectionOpacity
{
get => (double)GetValue(SelectionOpacityProperty);
set => SetValue(SelectionOpacityProperty, value);
}
public static readonly DependencyProperty CaretBrushProperty =
TextBoxBase.CaretBrushProperty.AddOwner(typeof(DateTimePicker));
public Brush CaretBrush
{
get => (Brush)GetValue(CaretBrushProperty);
set => SetValue(CaretBrushProperty, value);
}
#endregion
#region Public Methods
@@ -316,31 +358,40 @@ namespace HandyControl.Controls
_dropDownButton.Click += DropDownButton_Click;
_dropDownButton.MouseLeave += DropDownButton_MouseLeave;
if (SelectedDateTime == null)
{
_textBox.Text = DateTime.Now.ToString(DateTimeFormat);
}
_textBox.KeyDown += TextBox_KeyDown;
_textBox.TextChanged += TextBox_TextChanged;
_textBox.LostFocus += TextBox_LostFocus;
if (SelectedDateTime == null)
if (_textBox != null)
{
if (!string.IsNullOrEmpty(_defaultText))
if (SelectedDateTime == null)
{
_textBox.Text = _defaultText;
SetSelectedDateTime();
_textBox.Text = DateTime.Now.ToString(DateTimeFormat);
}
_textBox.SetBinding(SelectionBrushProperty, new Binding(SelectionBrushProperty.Name) { Source = this });
#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
_textBox.SetBinding(SelectionTextBrushProperty, new Binding(SelectionTextBrushProperty.Name) { Source = this });
#endif
_textBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
_textBox.SetBinding(CaretBrushProperty, new Binding(CaretBrushProperty.Name) { Source = this });
_textBox.KeyDown += TextBox_KeyDown;
_textBox.TextChanged += TextBox_TextChanged;
_textBox.LostFocus += TextBox_LostFocus;
if (SelectedDateTime == null)
{
if (!string.IsNullOrEmpty(_defaultText))
{
_textBox.Text = _defaultText;
SetSelectedDateTime();
}
}
else
{
_textBox.Text = DateTimeToString(SelectedDateTime.Value);
}
}
else
{
_textBox.Text = DateTimeToString(SelectedDateTime.Value);
}
if (_originalSelectedDateTime == null)
{
_originalSelectedDateTime = DateTime.Now;
}
_originalSelectedDateTime ??= DateTime.Now;
SetCurrentValue(DisplayDateTimeProperty, _originalSelectedDateTime);
}
@@ -424,11 +475,7 @@ namespace HandyControl.Controls
{
if (value)
{
if (_isHandlerSuspended == null)
{
_isHandlerSuspended = new Dictionary<DependencyProperty, bool>(2);
}
_isHandlerSuspended ??= new Dictionary<DependencyProperty, bool>(2);
_isHandlerSuspended[property] = true;
}
else