From aece5e3a44dd3ec09c2016b2a85bac24b969336e Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Sat, 17 Nov 2018 16:58:11 +0800
Subject: [PATCH] enhance the function of ComboBox
---
HandyControl/Controls/Input/ComboBox.cs | 112 ++++
HandyControl/Controls/Input/NumericUpDown.cs | 7 +-
HandyControl/Controls/Input/TextBox.cs | 2 +-
HandyControl/HandyControl.csproj | 1 +
.../Themes/Styles/Base/ComboBoxBaseStyle.xaml | 521 ++++++++++++++++--
.../Themes/Styles/Base/TextBoxBaseStyle.xaml | 204 ++++++-
HandyControl/Themes/Styles/ComboBox.xaml | 5 +-
HandyControl/Themes/Styles/TextBox.xaml | 204 +------
HandyControlDemo/Data/MessageToken.cs | 4 +-
HandyControlDemo/Data/MessageToken.tt | 5 +-
HandyControlDemo/HandyControlDemo.csproj | 13 +-
.../UserControl/Controls/ComboBoxDemoCtl.xaml | 27 +
.../ComboBoxDemoCtl.xaml.cs | 3 +-
.../UserControl/Main/LeftMainContent.xaml | 7 +-
...DemoCtl.xaml => NaiveComboBoxDemoCtl.xaml} | 2 +-
.../Styles/NaiveComboBoxDemoCtl.xaml.cs | 10 +
16 files changed, 868 insertions(+), 259 deletions(-)
create mode 100644 HandyControl/Controls/Input/ComboBox.cs
create mode 100644 HandyControlDemo/UserControl/Controls/ComboBoxDemoCtl.xaml
rename HandyControlDemo/UserControl/{Styles => Controls}/ComboBoxDemoCtl.xaml.cs (63%)
rename HandyControlDemo/UserControl/Styles/{ComboBoxDemoCtl.xaml => NaiveComboBoxDemoCtl.xaml} (97%)
create mode 100644 HandyControlDemo/UserControl/Styles/NaiveComboBoxDemoCtl.xaml.cs
diff --git a/HandyControl/Controls/Input/ComboBox.cs b/HandyControl/Controls/Input/ComboBox.cs
new file mode 100644
index 00000000..3eb05716
--- /dev/null
+++ b/HandyControl/Controls/Input/ComboBox.cs
@@ -0,0 +1,112 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using HandyControl.Data;
+using HandyControl.Interactivity;
+
+namespace HandyControl.Controls
+{
+ ///
+ public class ComboBox : System.Windows.Controls.ComboBox, IDataInput
+ {
+ public ComboBox()
+ {
+ CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) =>
+ {
+ ClearValue(SelectedValueProperty);
+ ClearValue(SelectedItemProperty);
+ ClearValue(SelectedIndexProperty);
+ ClearValue(TextProperty);
+ }));
+ }
+
+ protected override void OnSelectionChanged(SelectionChangedEventArgs e)
+ {
+ base.OnSelectionChanged(e);
+ VerifyData();
+ }
+
+ public Func> VerifyFunc { get; set; }
+
+ ///
+ /// 数据是否错误
+ ///
+ public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register(
+ "IsError", typeof(bool), typeof(ComboBox), new PropertyMetadata(default(bool)));
+
+ public bool IsError
+ {
+ get => (bool) GetValue(IsErrorProperty);
+ set => SetValue(IsErrorProperty, value);
+ }
+
+ ///
+ /// 错误提示
+ ///
+ public static readonly DependencyProperty ErrorStrProperty = DependencyProperty.Register(
+ "ErrorStr", typeof(string), typeof(ComboBox), new PropertyMetadata(default(string)));
+
+ public string ErrorStr
+ {
+ get => (string) GetValue(ErrorStrProperty);
+ set => SetValue(ErrorStrProperty, value);
+ }
+
+ public static readonly DependencyPropertyKey TextTypePropertyKey =
+ DependencyProperty.RegisterReadOnly("TextType", typeof(TextType), typeof(ComboBox),
+ new PropertyMetadata(default(TextType)));
+
+ ///
+ /// 文本类型
+ ///
+ public static readonly DependencyProperty TextTypeProperty = TextTypePropertyKey.DependencyProperty;
+
+ public TextType TextType
+ {
+ get => (TextType) GetValue(TextTypeProperty);
+ set => SetValue(TextTypeProperty, value);
+ }
+
+ ///
+ /// 是否显示清除按钮
+ ///
+ public static readonly DependencyProperty ShowClearButtonProperty = DependencyProperty.Register(
+ "ShowClearButton", typeof(bool), typeof(ComboBox), new PropertyMetadata(default(bool)));
+
+ 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/NumericUpDown.cs b/HandyControl/Controls/Input/NumericUpDown.cs
index 78b902e0..f6b70ca5 100644
--- a/HandyControl/Controls/Input/NumericUpDown.cs
+++ b/HandyControl/Controls/Input/NumericUpDown.cs
@@ -336,11 +336,14 @@ namespace HandyControl.Controls
set => SetValue(ErrorStrProperty, value);
}
+ public static readonly DependencyPropertyKey TextTypePropertyKey =
+ DependencyProperty.RegisterReadOnly("TextType", typeof(TextType), typeof(NumericUpDown),
+ new PropertyMetadata(default(TextType)));
+
///
/// 文本类型
///
- public static readonly DependencyProperty TextTypeProperty = DependencyProperty.Register(
- "TextType", typeof(TextType), typeof(NumericUpDown), new PropertyMetadata(default(TextType)));
+ public static readonly DependencyProperty TextTypeProperty = TextTypePropertyKey.DependencyProperty;
public TextType TextType
{
diff --git a/HandyControl/Controls/Input/TextBox.cs b/HandyControl/Controls/Input/TextBox.cs
index 815e6ade..2216919c 100644
--- a/HandyControl/Controls/Input/TextBox.cs
+++ b/HandyControl/Controls/Input/TextBox.cs
@@ -9,6 +9,7 @@ using HandyControl.Tools;
// ReSharper disable once CheckNamespace
namespace HandyControl.Controls
{
+ ///
public class TextBox : System.Windows.Controls.TextBox, IDataInput
{
public TextBox()
@@ -16,7 +17,6 @@ namespace HandyControl.Controls
CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) =>
{
ClearValue(TextProperty);
- Text = string.Empty;
}));
}
diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj
index 772869a8..dbdfa326 100644
--- a/HandyControl/HandyControl.csproj
+++ b/HandyControl/HandyControl.csproj
@@ -52,6 +52,7 @@
+
diff --git a/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml b/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml
index 472fb1e8..fd89b9ec 100644
--- a/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml
+++ b/HandyControl/Themes/Styles/Base/ComboBoxBaseStyle.xaml
@@ -1,14 +1,17 @@
+ xmlns:system="clr-namespace:System;assembly=mscorlib"
+ xmlns:interactivity="clr-namespace:HandyControl.Interactivity">
+
+
+
+
@@ -101,19 +106,13 @@
-
-
-
-
-
-
-
+
@@ -165,19 +164,13 @@
-
-
-
-
-
-
-
+
@@ -226,19 +219,13 @@
-
-
-
-
-
-
-
+
+
@@ -309,19 +297,13 @@
-
-
-
-
-
-
-
+
@@ -383,19 +365,13 @@
-
-
-
-
-
-
-
+
@@ -454,19 +430,13 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/HandyControl/Themes/Styles/Base/TextBoxBaseStyle.xaml b/HandyControl/Themes/Styles/Base/TextBoxBaseStyle.xaml
index 5c9b4981..a7cf49e3 100644
--- a/HandyControl/Themes/Styles/Base/TextBoxBaseStyle.xaml
+++ b/HandyControl/Themes/Styles/Base/TextBoxBaseStyle.xaml
@@ -1,9 +1,14 @@
+ xmlns:controls="clr-namespace:HandyControl.Controls"
+ xmlns:system="clr-namespace:System;assembly=mscorlib"
+ xmlns:interactivity="clr-namespace:HandyControl.Interactivity">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/HandyControl/Themes/Styles/ComboBox.xaml b/HandyControl/Themes/Styles/ComboBox.xaml
index c69e3a70..f623cfb3 100644
--- a/HandyControl/Themes/Styles/ComboBox.xaml
+++ b/HandyControl/Themes/Styles/ComboBox.xaml
@@ -1,5 +1,6 @@
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:controls="clr-namespace:HandyControl.Controls">
@@ -9,4 +10,6 @@
+
+
\ No newline at end of file
diff --git a/HandyControl/Themes/Styles/TextBox.xaml b/HandyControl/Themes/Styles/TextBox.xaml
index 0692ea55..a90b6bc9 100644
--- a/HandyControl/Themes/Styles/TextBox.xaml
+++ b/HandyControl/Themes/Styles/TextBox.xaml
@@ -1,215 +1,17 @@
+ xmlns:controls="clr-namespace:HandyControl.Controls">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/HandyControlDemo/Data/MessageToken.cs b/HandyControlDemo/Data/MessageToken.cs
index b8105dbe..b74483b8 100644
--- a/HandyControlDemo/Data/MessageToken.cs
+++ b/HandyControlDemo/Data/MessageToken.cs
@@ -40,6 +40,8 @@
public static readonly string TextBoxDemoCtl = nameof(TextBoxDemoCtl);
+ public static readonly string ComboBoxDemoCtl = nameof(ComboBoxDemoCtl);
+
public static readonly string ButtonDemoCtl = nameof(ButtonDemoCtl);
public static readonly string ToggleButtonDemoCtl = nameof(ToggleButtonDemoCtl);
@@ -58,7 +60,7 @@
public static readonly string TextBlockDemoCtl = nameof(TextBlockDemoCtl);
- public static readonly string ComboBoxDemoCtl = nameof(ComboBoxDemoCtl);
+ public static readonly string NaiveComboBoxDemoCtl = nameof(NaiveComboBoxDemoCtl);
public static readonly string PasswordBoxDemoCtl = nameof(PasswordBoxDemoCtl);
diff --git a/HandyControlDemo/Data/MessageToken.tt b/HandyControlDemo/Data/MessageToken.tt
index e558d7c2..68d36bb8 100644
--- a/HandyControlDemo/Data/MessageToken.tt
+++ b/HandyControlDemo/Data/MessageToken.tt
@@ -22,7 +22,8 @@ var controlList = new List
"ScrollViewerDemoCtl",
"PreviewSliderDemoCtl",
"CircleProgressBarDemoCtl",
- "TextBoxDemoCtl"
+ "TextBoxDemoCtl",
+ "ComboBoxDemoCtl"
};
var styleList = new List
{
@@ -35,7 +36,7 @@ var styleList = new List
"DatePickerDemoCtl",
"NaiveTextBoxDemoCtl",
"TextBlockDemoCtl",
- "ComboBoxDemoCtl",
+ "NaiveComboBoxDemoCtl",
"PasswordBoxDemoCtl",
"NaiveTabControlDemoCtl",
"DataGridDemoCtl",
diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj
index 35354266..63b62b18 100644
--- a/HandyControlDemo/HandyControlDemo.csproj
+++ b/HandyControlDemo/HandyControlDemo.csproj
@@ -114,6 +114,9 @@
ColorPickerDemoCtl.xaml
+
+ ComboBoxDemoCtl.xaml
+
CompareSliderDemoCtl.xaml
@@ -168,8 +171,8 @@
CheckBoxDemoCtl.xaml
-
- ComboBoxDemoCtl.xaml
+
+ NaiveComboBoxDemoCtl.xaml
DataGridDemoCtl.xaml
@@ -330,6 +333,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
@@ -402,7 +409,7 @@
Designer
MSBuild:Compile
-
+
Designer
MSBuild:Compile
diff --git a/HandyControlDemo/UserControl/Controls/ComboBoxDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/ComboBoxDemoCtl.xaml
new file mode 100644
index 00000000..045e2025
--- /dev/null
+++ b/HandyControlDemo/UserControl/Controls/ComboBoxDemoCtl.xaml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/HandyControlDemo/UserControl/Styles/ComboBoxDemoCtl.xaml.cs b/HandyControlDemo/UserControl/Controls/ComboBoxDemoCtl.xaml.cs
similarity index 63%
rename from HandyControlDemo/UserControl/Styles/ComboBoxDemoCtl.xaml.cs
rename to HandyControlDemo/UserControl/Controls/ComboBoxDemoCtl.xaml.cs
index 7ed05820..95f82acf 100644
--- a/HandyControlDemo/UserControl/Styles/ComboBoxDemoCtl.xaml.cs
+++ b/HandyControlDemo/UserControl/Controls/ComboBoxDemoCtl.xaml.cs
@@ -1,5 +1,4 @@
-// ReSharper disable once CheckNamespace
-namespace HandyControlDemo.UserControl
+namespace HandyControlDemo.UserControl
{
public partial class ComboBoxDemoCtl
{
diff --git a/HandyControlDemo/UserControl/Main/LeftMainContent.xaml b/HandyControlDemo/UserControl/Main/LeftMainContent.xaml
index 3d89263f..513a289f 100644
--- a/HandyControlDemo/UserControl/Main/LeftMainContent.xaml
+++ b/HandyControlDemo/UserControl/Main/LeftMainContent.xaml
@@ -60,7 +60,7 @@
-
+
@@ -134,6 +134,11 @@
+
+
+
+
+
diff --git a/HandyControlDemo/UserControl/Styles/ComboBoxDemoCtl.xaml b/HandyControlDemo/UserControl/Styles/NaiveComboBoxDemoCtl.xaml
similarity index 97%
rename from HandyControlDemo/UserControl/Styles/ComboBoxDemoCtl.xaml
rename to HandyControlDemo/UserControl/Styles/NaiveComboBoxDemoCtl.xaml
index a7c191ee..377a8d1f 100644
--- a/HandyControlDemo/UserControl/Styles/ComboBoxDemoCtl.xaml
+++ b/HandyControlDemo/UserControl/Styles/NaiveComboBoxDemoCtl.xaml
@@ -1,4 +1,4 @@
-