diff --git a/HandyControl/Controls/Input/DatePicker.cs b/HandyControl/Controls/Input/DatePicker.cs new file mode 100644 index 00000000..993541ec --- /dev/null +++ b/HandyControl/Controls/Input/DatePicker.cs @@ -0,0 +1,113 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Input; +using HandyControl.Data; +using HandyControl.Interactivity; + +namespace HandyControl.Controls +{ + /// + [TemplatePart(Name = ElementTextBox, Type = typeof(DatePickerTextBox))] + public class DatePicker : System.Windows.Controls.DatePicker, IDataInput + { + private const string ElementTextBox = "PART_TextBox"; + + private System.Windows.Controls.TextBox _textBox; + + public DatePicker() + { + CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) => + { + ClearValue(SelectedDateProperty); + ClearValue(TextProperty); + })); + } + + public override void OnApplyTemplate() + { + if (_textBox != null) + { + _textBox.TextChanged -= TextBox_TextChanged; + } + + base.OnApplyTemplate(); + + _textBox = GetTemplateChild(ElementTextBox) as System.Windows.Controls.TextBox; + if (_textBox != null) + { + _textBox.TextChanged += TextBox_TextChanged; + } + } + + private void TextBox_TextChanged(object sender, TextChangedEventArgs e) => VerifyData(); + + public Func> VerifyFunc { get; set; } + + public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register( + "IsError", typeof(bool), typeof(DatePicker), new PropertyMetadata(ValueBoxes.FalseBox)); + + public bool IsError + { + get => (bool) GetValue(IsErrorProperty); + set => SetValue(IsErrorProperty, value); + } + + public static readonly DependencyProperty ErrorStrProperty = DependencyProperty.Register( + "ErrorStr", typeof(string), typeof(DatePicker), new PropertyMetadata(default(string))); + + public string ErrorStr + { + get => (string) GetValue(ErrorStrProperty); + set => SetValue(ErrorStrProperty, value); + } + + public static readonly DependencyProperty TextTypeProperty = DependencyProperty.Register( + "TextType", typeof(TextType), typeof(DatePicker), new PropertyMetadata(default(TextType))); + + public TextType TextType + { + get => (TextType) GetValue(TextTypeProperty); + set => SetValue(TextTypeProperty, value); + } + + public static readonly DependencyProperty ShowClearButtonProperty = DependencyProperty.Register( + "ShowClearButton", typeof(bool), typeof(DatePicker), new PropertyMetadata(ValueBoxes.FalseBox)); + + public bool ShowClearButton + { + get => (bool) GetValue(ShowClearButtonProperty); + set => SetValue(ShowClearButtonProperty, value); + } + + public virtual bool VerifyData() + { + OperationResult result; + + if (VerifyFunc != null) + { + result = VerifyFunc.Invoke(Text); + } + else + { + if (!string.IsNullOrEmpty(Text)) + { + 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/HandyControl/Controls/Input/PasswordBox.cs b/HandyControl/Controls/Input/PasswordBox.cs index 22e2168f..392fda2e 100644 --- a/HandyControl/Controls/Input/PasswordBox.cs +++ b/HandyControl/Controls/Input/PasswordBox.cs @@ -11,6 +11,7 @@ using HandyControl.Properties.Langs; namespace HandyControl.Controls { /// + [TemplatePart(Name = ElementPasswordBox, Type = typeof(System.Windows.Controls.PasswordBox))] public class PasswordBox : Control, IDataInput { private const string ElementPasswordBox = "PART_PasswordBox"; diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj index 52f78b16..11a33412 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -53,6 +53,7 @@ + diff --git a/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml b/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml index fd89b9ec..ac64b1b1 100644 --- a/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml @@ -29,6 +29,9 @@ + + + @@ -45,17 +48,21 @@ - - - - - - + + + + + + + + + + @@ -109,6 +116,9 @@ + + + @@ -167,6 +177,10 @@ + + + + @@ -222,6 +236,10 @@ + + + + @@ -300,6 +318,9 @@ + + + @@ -331,7 +352,7 @@ - + @@ -368,6 +389,11 @@ + + + + + @@ -396,7 +422,7 @@ - + @@ -433,6 +459,11 @@ + + + + + @@ -495,9 +526,6 @@ - - - @@ -627,6 +655,10 @@ + + + + @@ -722,6 +754,10 @@ + + + + @@ -762,7 +798,7 @@ - + @@ -844,6 +880,11 @@ + + + + + @@ -881,7 +922,7 @@ - + @@ -963,6 +1004,11 @@ + + + + + diff --git a/HandyControl/Themes/Styles/Base/DatePickerBaseStyle.xaml b/HandyControl/Themes/Styles/Base/DatePickerBaseStyle.xaml index d36a7acc..125bc1ae 100644 --- a/HandyControl/Themes/Styles/Base/DatePickerBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/DatePickerBaseStyle.xaml @@ -1,6 +1,8 @@  + xmlns:controls="clr-namespace:HandyControl.Controls" + xmlns:system="clr-namespace:System;assembly=mscorlib" + xmlns:interactivity="clr-namespace:HandyControl.Interactivity"> @@ -80,4 +82,279 @@ + + + + + + + + + + + + + + + + + +