From e8ecb7d6be929b4956f4641d4997212bf52e34bf Mon Sep 17 00:00:00 2001 From: varKeytrap Date: Wed, 6 May 2020 15:48:33 +0200 Subject: [PATCH] Added Custom support for TextType --- .../Controls/Input/TextBox.cs | 16 +++++++++++++++- .../HandyControl_Shared/Data/Enum/TextType.cs | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs b/src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs index 8cc0edf5..fb3c4cd2 100644 --- a/src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs +++ b/src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs @@ -1,4 +1,5 @@ using System; +using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -75,6 +76,16 @@ namespace HandyControl.Controls set => SetValue(ShowClearButtonProperty, value); } + public static readonly DependencyProperty TextTypeCustomRegexPatternProperty = DependencyProperty.Register( + "TextTypeCustomRegexPattern", typeof(string), typeof(TextBox), new PropertyMetadata(null)); + + public string TextTypeCustomRegexPattern + { + get => (string)GetValue(TextTypeCustomRegexPatternProperty); + set => SetValue(TextTypeCustomRegexPatternProperty, value); + } + + public virtual bool VerifyData() { OperationResult result; @@ -89,7 +100,10 @@ namespace HandyControl.Controls { if (TextType != TextType.Common) { - result = Text.IsKindOf(TextType) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError); + if (TextType == TextType.Custom && !string.IsNullOrEmpty(TextTypeCustomRegexPattern)) + result = Regex.IsMatch(Text, TextTypeCustomRegexPattern) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError); + else + result = Text.IsKindOf(TextType) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError); } else { diff --git a/src/Shared/HandyControl_Shared/Data/Enum/TextType.cs b/src/Shared/HandyControl_Shared/Data/Enum/TextType.cs index 19e51c3f..450b3ec5 100644 --- a/src/Shared/HandyControl_Shared/Data/Enum/TextType.cs +++ b/src/Shared/HandyControl_Shared/Data/Enum/TextType.cs @@ -23,5 +23,6 @@ namespace HandyControl.Data Double, NnDouble, NpDouble, + Custom } } \ No newline at end of file