diff --git a/src/Shared/HandyControl_Shared/Controls/Input/ComboBox.cs b/src/Shared/HandyControl_Shared/Controls/Input/ComboBox.cs
index 33b8b023..354bb1b7 100644
--- a/src/Shared/HandyControl_Shared/Controls/Input/ComboBox.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Input/ComboBox.cs
@@ -5,6 +5,7 @@ using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
+using System.Windows.Media;
#if NET40
using System.Windows.Threading;
#endif
@@ -69,6 +70,13 @@ namespace HandyControl.Controls
{
_editableTextBox.TextChanged += EditableTextBox_TextChanged;
+ _editableTextBox.SetBinding(SelectionBrushProperty, new Binding(SelectionBrushProperty.Name) { Source = this });
+#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
+ _editableTextBox.SetBinding(SelectionTextBrushProperty, new Binding(SelectionTextBrushProperty.Name) { Source = this });
+#endif
+ _editableTextBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
+ _editableTextBox.SetBinding(CaretBrushProperty, new Binding(CaretBrushProperty.Name) { Source = this });
+
if (AutoComplete)
{
#if NET40
@@ -238,6 +246,122 @@ namespace HandyControl.Controls
}
}
+ ///
+ /// 是否自动完成输入
+ ///
+ public bool AutoComplete
+ {
+ get => (bool)GetValue(AutoCompleteProperty);
+ set => SetValue(AutoCompleteProperty, ValueBoxes.BooleanBox(value));
+ }
+
+ ///
+ /// 搜索文本
+ ///
+ internal static readonly DependencyProperty SearchTextProperty = DependencyProperty.Register(
+ "SearchText", typeof(string), typeof(ComboBox), new PropertyMetadata(default(string), OnSearchTextChanged));
+
+ private static void OnSearchTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var ctl = (ComboBox)d;
+ if (ctl._isAutoCompleteAction)
+ {
+#if NET40
+ ctl._searchText = e.NewValue as string;
+ ctl._autoCompleteTimer.Stop();
+ ctl._autoCompleteTimer.Start();
+#else
+ ctl.UpdateSearchItems(e.NewValue as string);
+#endif
+ }
+
+ ctl._isAutoCompleteAction = true;
+ }
+
+ ///
+ /// 搜索文本
+ ///
+ internal string SearchText
+ {
+ get => (string)GetValue(SearchTextProperty);
+ set => SetValue(SearchTextProperty, value);
+ }
+
+ public static readonly DependencyProperty SelectionBrushProperty =
+ TextBoxBase.SelectionBrushProperty.AddOwner(typeof(ComboBox));
+
+ 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(ComboBox));
+
+ public Brush SelectionTextBrush
+ {
+ get => (Brush)GetValue(SelectionTextBrushProperty);
+ set => SetValue(SelectionTextBrushProperty, value);
+ }
+
+#endif
+
+ public static readonly DependencyProperty SelectionOpacityProperty =
+ TextBoxBase.SelectionOpacityProperty.AddOwner(typeof(ComboBox));
+
+ public double SelectionOpacity
+ {
+ get => (double)GetValue(SelectionOpacityProperty);
+ set => SetValue(SelectionOpacityProperty, value);
+ }
+
+ public static readonly DependencyProperty CaretBrushProperty =
+ TextBoxBase.CaretBrushProperty.AddOwner(typeof(ComboBox));
+
+ public Brush CaretBrush
+ {
+ get => (Brush)GetValue(CaretBrushProperty);
+ set => SetValue(CaretBrushProperty, value);
+ }
+
+ ///
+ /// 验证数据
+ ///
+ ///
+ public virtual bool VerifyData()
+ {
+ OperationResult result;
+
+ var value = _editableTextBox == null ? Text : _editableTextBox.Text;
+
+ if (VerifyFunc != null)
+ {
+ result = VerifyFunc.Invoke(value);
+ }
+ else
+ {
+ if (!string.IsNullOrEmpty(value))
+ {
+ result = OperationResult.Success();
+ }
+ else if (InfoElement.GetNecessary(this))
+ {
+ result = OperationResult.Failed(Properties.Langs.Lang.IsNecessary);
+ }
+ else
+ {
+ result = OperationResult.Success();
+ }
+ }
+
+ IsError = !result.Data;
+ ErrorStr = result.Message;
+ return result.Data;
+ }
+
///
/// 更新搜索的项目
///
@@ -300,81 +424,5 @@ namespace HandyControl.Controls
SelectedValue = comboBoxItem.Content;
}
}
-
- ///
- /// 搜索文本
- ///
- internal static readonly DependencyProperty SearchTextProperty = DependencyProperty.Register(
- "SearchText", typeof(string), typeof(ComboBox), new PropertyMetadata(default(string), OnSearchTextChanged));
-
- private static void OnSearchTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var ctl = (ComboBox)d;
- if (ctl._isAutoCompleteAction)
- {
-#if NET40
- ctl._searchText = e.NewValue as string;
- ctl._autoCompleteTimer.Stop();
- ctl._autoCompleteTimer.Start();
-#else
- ctl.UpdateSearchItems(e.NewValue as string);
-#endif
- }
-
- ctl._isAutoCompleteAction = true;
- }
-
- ///
- /// 搜索文本
- ///
- internal string SearchText
- {
- get => (string)GetValue(SearchTextProperty);
- set => SetValue(SearchTextProperty, value);
- }
-
- ///
- /// 是否自动完成输入
- ///
- public bool AutoComplete
- {
- get => (bool)GetValue(AutoCompleteProperty);
- set => SetValue(AutoCompleteProperty, ValueBoxes.BooleanBox(value));
- }
-
- ///
- /// 验证数据
- ///
- ///
- public virtual bool VerifyData()
- {
- OperationResult result;
-
- var value = _editableTextBox == null ? Text : _editableTextBox.Text;
-
- if (VerifyFunc != null)
- {
- result = VerifyFunc.Invoke(value);
- }
- else
- {
- if (!string.IsNullOrEmpty(value))
- {
- result = OperationResult.Success();
- }
- else if (InfoElement.GetNecessary(this))
- {
- result = OperationResult.Failed(Properties.Langs.Lang.IsNecessary);
- }
- else
- {
- result = OperationResult.Success();
- }
- }
-
- IsError = !result.Data;
- ErrorStr = result.Message;
- return result.Data;
- }
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/Input/DatePicker.cs b/src/Shared/HandyControl_Shared/Controls/Input/DatePicker.cs
index 79efb304..61f670ed 100644
--- a/src/Shared/HandyControl_Shared/Controls/Input/DatePicker.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Input/DatePicker.cs
@@ -2,7 +2,9 @@
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 HandyControl.Data;
using HandyControl.Interactivity;
@@ -36,6 +38,13 @@ namespace HandyControl.Controls
_textBox = GetTemplateChild(ElementTextBox) as System.Windows.Controls.TextBox;
if (_textBox != null)
{
+ _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.TextChanged += TextBox_TextChanged;
}
}
@@ -80,6 +89,46 @@ namespace HandyControl.Controls
set => SetValue(ShowClearButtonProperty, ValueBoxes.BooleanBox(value));
}
+ public static readonly DependencyProperty SelectionBrushProperty =
+ TextBoxBase.SelectionBrushProperty.AddOwner(typeof(DatePicker));
+
+ 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(DatePicker));
+
+ public Brush SelectionTextBrush
+ {
+ get => (Brush)GetValue(SelectionTextBrushProperty);
+ set => SetValue(SelectionTextBrushProperty, value);
+ }
+
+#endif
+
+ public static readonly DependencyProperty SelectionOpacityProperty =
+ TextBoxBase.SelectionOpacityProperty.AddOwner(typeof(DatePicker));
+
+ public double SelectionOpacity
+ {
+ get => (double)GetValue(SelectionOpacityProperty);
+ set => SetValue(SelectionOpacityProperty, value);
+ }
+
+ public static readonly DependencyProperty CaretBrushProperty =
+ TextBoxBase.CaretBrushProperty.AddOwner(typeof(DatePicker));
+
+ public Brush CaretBrush
+ {
+ get => (Brush)GetValue(CaretBrushProperty);
+ set => SetValue(CaretBrushProperty, value);
+ }
+
public virtual bool VerifyData()
{
OperationResult result;
diff --git a/src/Shared/HandyControl_Shared/Controls/Input/DateTimePicker.cs b/src/Shared/HandyControl_Shared/Controls/Input/DateTimePicker.cs
index 2379474d..2b902401 100644
--- a/src/Shared/HandyControl_Shared/Controls/Input/DateTimePicker.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Input/DateTimePicker.cs
@@ -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(2);
- }
-
+ _isHandlerSuspended ??= new Dictionary(2);
_isHandlerSuspended[property] = true;
}
else
diff --git a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs
index 32c6c0c9..28dbba39 100644
--- a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs
@@ -1,7 +1,10 @@
using System;
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 HandyControl.Data;
using HandyControl.Interactivity;
using HandyControl.Tools;
@@ -85,6 +88,13 @@ namespace HandyControl.Controls
if (_textBox != null)
{
+ _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 });
+
TextCompositionManager.AddPreviewTextInputHandler(_textBox, PreviewTextInputHandler);
_textBox.TextChanged += TextBox_TextChanged;
_textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
@@ -389,6 +399,46 @@ namespace HandyControl.Controls
set => SetValue(IsReadOnlyProperty, ValueBoxes.BooleanBox(value));
}
+ public static readonly DependencyProperty SelectionBrushProperty =
+ TextBoxBase.SelectionBrushProperty.AddOwner(typeof(NumericUpDown));
+
+ 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(NumericUpDown));
+
+ public Brush SelectionTextBrush
+ {
+ get => (Brush)GetValue(SelectionTextBrushProperty);
+ set => SetValue(SelectionTextBrushProperty, value);
+ }
+
+#endif
+
+ public static readonly DependencyProperty SelectionOpacityProperty =
+ TextBoxBase.SelectionOpacityProperty.AddOwner(typeof(NumericUpDown));
+
+ public double SelectionOpacity
+ {
+ get => (double)GetValue(SelectionOpacityProperty);
+ set => SetValue(SelectionOpacityProperty, value);
+ }
+
+ public static readonly DependencyProperty CaretBrushProperty =
+ TextBoxBase.CaretBrushProperty.AddOwner(typeof(NumericUpDown));
+
+ public Brush CaretBrush
+ {
+ get => (Brush)GetValue(CaretBrushProperty);
+ set => SetValue(CaretBrushProperty, value);
+ }
+
public Func> VerifyFunc { get; set; }
public virtual bool VerifyData()
diff --git a/src/Shared/HandyControl_Shared/Controls/Input/PinBox.cs b/src/Shared/HandyControl_Shared/Controls/Input/PinBox.cs
index 5fe2fc94..028d822a 100644
--- a/src/Shared/HandyControl_Shared/Controls/Input/PinBox.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Input/PinBox.cs
@@ -5,7 +5,10 @@ using System.Runtime.InteropServices;
using System.Security;
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 HandyControl.Data;
using HandyControl.Tools;
using HandyControl.Tools.Extension;
@@ -256,6 +259,46 @@ namespace HandyControl.Controls
set => SetValue(ItemHeightProperty, value);
}
+ public static readonly DependencyProperty SelectionBrushProperty =
+ TextBoxBase.SelectionBrushProperty.AddOwner(typeof(PinBox));
+
+ 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(PinBox));
+
+ public Brush SelectionTextBrush
+ {
+ get => (Brush)GetValue(SelectionTextBrushProperty);
+ set => SetValue(SelectionTextBrushProperty, value);
+ }
+
+#endif
+
+ public static readonly DependencyProperty SelectionOpacityProperty =
+ TextBoxBase.SelectionOpacityProperty.AddOwner(typeof(PinBox));
+
+ public double SelectionOpacity
+ {
+ get => (double)GetValue(SelectionOpacityProperty);
+ set => SetValue(SelectionOpacityProperty, value);
+ }
+
+ public static readonly DependencyProperty CaretBrushProperty =
+ TextBoxBase.CaretBrushProperty.AddOwner(typeof(PinBox));
+
+ public Brush CaretBrush
+ {
+ get => (Brush)GetValue(CaretBrushProperty);
+ set => SetValue(CaretBrushProperty, value);
+ }
+
public static readonly RoutedEvent CompletedEvent =
EventManager.RegisterRoutedEvent("Completed", RoutingStrategy.Bubble,
typeof(RoutedEventHandler), typeof(PinBox));
@@ -281,7 +324,7 @@ namespace HandyControl.Controls
private System.Windows.Controls.PasswordBox CreatePasswordBox()
{
- return new System.Windows.Controls.PasswordBox
+ var passwordBox = new System.Windows.Controls.PasswordBox
{
MaxLength = 1,
HorizontalContentAlignment = HorizontalAlignment.Center,
@@ -290,8 +333,18 @@ namespace HandyControl.Controls
Width = ItemWidth,
Height = ItemHeight,
Padding = default,
- PasswordChar = PasswordChar
+ PasswordChar = PasswordChar,
+ Foreground = Foreground
};
+
+ passwordBox.SetBinding(SelectionBrushProperty, new Binding(SelectionBrushProperty.Name) { Source = this });
+#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
+ passwordBox.SetBinding(SelectionTextBrushProperty, new Binding(SelectionTextBrushProperty.Name) { Source = this });
+#endif
+ passwordBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
+ passwordBox.SetBinding(CaretBrushProperty, new Binding(CaretBrushProperty.Name) { Source = this });
+
+ return passwordBox;
}
public override void OnApplyTemplate()
diff --git a/src/Shared/HandyControl_Shared/Controls/Input/TimePicker.cs b/src/Shared/HandyControl_Shared/Controls/Input/TimePicker.cs
index 249f4746..b3019325 100644
--- a/src/Shared/HandyControl_Shared/Controls/Input/TimePicker.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Input/TimePicker.cs
@@ -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;
@@ -292,6 +294,46 @@ namespace HandyControl.Controls
set => SetValue(ShowClearButtonProperty, ValueBoxes.BooleanBox(value));
}
+ public static readonly DependencyProperty SelectionBrushProperty =
+ TextBoxBase.SelectionBrushProperty.AddOwner(typeof(TimePicker));
+
+ 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(TimePicker));
+
+ public Brush SelectionTextBrush
+ {
+ get => (Brush)GetValue(SelectionTextBrushProperty);
+ set => SetValue(SelectionTextBrushProperty, value);
+ }
+
+#endif
+
+ public static readonly DependencyProperty SelectionOpacityProperty =
+ TextBoxBase.SelectionOpacityProperty.AddOwner(typeof(TimePicker));
+
+ public double SelectionOpacity
+ {
+ get => (double)GetValue(SelectionOpacityProperty);
+ set => SetValue(SelectionOpacityProperty, value);
+ }
+
+ public static readonly DependencyProperty CaretBrushProperty =
+ TextBoxBase.CaretBrushProperty.AddOwner(typeof(TimePicker));
+
+ public Brush CaretBrush
+ {
+ get => (Brush)GetValue(CaretBrushProperty);
+ set => SetValue(CaretBrushProperty, value);
+ }
+
public static readonly DependencyProperty ClockProperty = DependencyProperty.Register(
"Clock", typeof(ClockBase), typeof(TimePicker), new FrameworkPropertyMetadata(default(Clock), FrameworkPropertyMetadataOptions.NotDataBindable, OnClockChanged));
@@ -398,31 +440,40 @@ namespace HandyControl.Controls
_dropDownButton.Click += DropDownButton_Click;
_dropDownButton.MouseLeave += DropDownButton_MouseLeave;
- if (SelectedTime == null)
- {
- _textBox.Text = DateTime.Now.ToString(TimeFormat);
- }
- _textBox.KeyDown += TextBox_KeyDown;
- _textBox.TextChanged += TextBox_TextChanged;
- _textBox.LostFocus += TextBox_LostFocus;
- if (SelectedTime == null)
+ if (_textBox != null)
{
- if (!string.IsNullOrEmpty(_defaultText))
+ if (SelectedTime == null)
{
- _textBox.Text = _defaultText;
- SetSelectedTime();
+ _textBox.Text = DateTime.Now.ToString(TimeFormat);
+ }
+
+ _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 (SelectedTime == null)
+ {
+ if (!string.IsNullOrEmpty(_defaultText))
+ {
+ _textBox.Text = _defaultText;
+ SetSelectedTime();
+ }
+ }
+ else
+ {
+ _textBox.Text = DateTimeToString((DateTime)SelectedTime);
}
}
- else
- {
- _textBox.Text = DateTimeToString((DateTime)SelectedTime);
- }
- if (_originalSelectedTime == null)
- {
- _originalSelectedTime = DateTime.Now;
- }
+ _originalSelectedTime ??= DateTime.Now;
SetCurrentValue(DisplayTimeProperty, _originalSelectedTime);
}
@@ -460,11 +511,7 @@ namespace HandyControl.Controls
{
if (value)
{
- if (_isHandlerSuspended == null)
- {
- _isHandlerSuspended = new Dictionary(2);
- }
-
+ _isHandlerSuspended ??= new Dictionary(2);
_isHandlerSuspended[property] = true;
}
else
diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/DateTimePickerBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/DateTimePickerBaseStyle.xaml
index 921fbdda..e1495709 100644
--- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/DateTimePickerBaseStyle.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/DateTimePickerBaseStyle.xaml
@@ -30,7 +30,7 @@
-
+
@@ -81,7 +81,7 @@
-
+
@@ -130,7 +130,7 @@
-
+
@@ -204,7 +204,7 @@
-
+
@@ -280,7 +280,7 @@
-
+
diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/TimePickerBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/TimePickerBaseStyle.xaml
index 86ce0c25..e3a821be 100644
--- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/TimePickerBaseStyle.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/TimePickerBaseStyle.xaml
@@ -30,7 +30,7 @@
-
+
@@ -81,7 +81,7 @@
-
+
@@ -130,7 +130,7 @@
-
+
@@ -204,7 +204,7 @@
-
+
@@ -280,7 +280,7 @@
-
+