diff --git a/src/Shared/HandyControl_Shared/Controls/Extra/PersianCalendar/DatePicker/Microsoft/Windows/Controls/PersianDatePicker.cs b/src/Shared/HandyControl_Shared/Controls/Extra/PersianCalendar/DatePicker/Microsoft/Windows/Controls/PersianDatePicker.cs index a87a20750..876e0d315 100644 --- a/src/Shared/HandyControl_Shared/Controls/Extra/PersianCalendar/DatePicker/Microsoft/Windows/Controls/PersianDatePicker.cs +++ b/src/Shared/HandyControl_Shared/Controls/Extra/PersianCalendar/DatePicker/Microsoft/Windows/Controls/PersianDatePicker.cs @@ -16,6 +16,7 @@ using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Input; +using System.Windows.Media; using System.Windows.Threading; using CalendarBlackoutDatesCollection = Microsoft.Windows.Controls.CalendarBlackoutDatesCollection; using CalendarDateChangedEventArgs = Microsoft.Windows.Controls.CalendarDateChangedEventArgs; @@ -39,6 +40,46 @@ namespace HandyControl.Controls [TemplateVisualState(Name = VisualStates.StateDisabled, GroupName = VisualStates.GroupCommon)] public class PersianDatePicker : Control { + 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); + } + #region Constants private const string ElementRoot = "PART_Root"; @@ -765,6 +806,13 @@ public override void OnApplyTemplate() _textBox.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged), true); _textBox.AddHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus), true); + _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 }); + if (SelectedDate == null) { if (!string.IsNullOrEmpty(_defaultText)) diff --git a/src/Shared/HandyControl_Shared/Controls/Extra/PersianCalendar/PersianDateTimePicker.cs b/src/Shared/HandyControl_Shared/Controls/Extra/PersianCalendar/PersianDateTimePicker.cs index 3f2a1d50e..1d6bea5c3 100644 --- a/src/Shared/HandyControl_Shared/Controls/Extra/PersianCalendar/PersianDateTimePicker.cs +++ b/src/Shared/HandyControl_Shared/Controls/Extra/PersianCalendar/PersianDateTimePicker.cs @@ -4,7 +4,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 System.Windows.Threading; using HandyControl.Data; using HandyControl.Interactivity; @@ -20,6 +22,46 @@ namespace HandyControl.Controls [TemplatePart(Name = ElementPopup, Type = typeof(Popup))] public class PersianDateTimePicker : Control, IDataInput { + 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); + } + #region Constants private const string ElementRoot = "PART_Root"; @@ -316,31 +358,39 @@ public override void OnApplyTemplate() _dropDownButton.Click += DropDownButton_Click; _dropDownButton.MouseLeave += DropDownButton_MouseLeave; - if (SelectedDateTime == null) + if (_textBox != null) { - _textBox.Text = DateTime.Now.ToString(DateTimeFormat); - } - _textBox.KeyDown += TextBox_KeyDown; - _textBox.TextChanged += TextBox_TextChanged; - _textBox.LostFocus += TextBox_LostFocus; + if (SelectedDateTime == null) + { + _textBox.Text = DateTime.Now.ToString(DateTimeFormat); + } - if (SelectedDateTime == null) - { - if (!string.IsNullOrEmpty(_defaultText)) + _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) { - _textBox.Text = _defaultText; - SetSelectedDateTime(); + 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); } diff --git a/src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs b/src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs index d28c1f56a..3109d5c96 100644 --- a/src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs +++ b/src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Media; +using System.Runtime.CompilerServices; using System.Text; using System.Windows; using System.Windows.Controls; @@ -500,7 +501,7 @@ private static void SetButtonStatus(MessageBox messageBox, MessageBoxButton mess { IsCancel = true, IsDefault = true, - Content = ConfirmContent, + Content = messageBox.ConfirmContent, Command = ControlCommands.Confirm, Style = ResourceHelper.GetResource