From 82c6509c7ad028b045705b04180cb40440e6ece4 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Fri, 12 Oct 2018 20:03:59 +0800 Subject: [PATCH] refactor ImageBrowser, add NumericUpDown, delete info controls --- HandyControl/Controls/Info/InfoControl.cs | 374 ------------------ .../Controls/Info/InfoNumericUpDown.xaml | 66 ---- .../Controls/Info/InfoNumericUpDown.xaml.cs | 181 --------- HandyControl/Controls/Info/InfoTextBox.xaml | 62 --- .../Controls/Info/InfoTextBox.xaml.cs | 45 --- HandyControl/Controls/NumericUpDown.cs | 257 ++++++++++++ HandyControl/Controls/Picker/ColorPicker.xaml | 25 +- .../Controls/Picker/ColorPicker.xaml.cs | 5 +- HandyControl/Controls/TimeBar/TimeBar.cs | 3 +- .../{ImageBrowser.xaml.cs => ImageBrowser.cs} | 241 +++++++---- .../Controls/Window/ImageBrowser.xaml | 81 ---- HandyControl/HandyControl.csproj | 35 +- HandyControl/Interactivity/ControlCommands.cs | 37 +- HandyControl/Properties/AssemblyInfo.cs | 4 +- HandyControl/Resources/colorPickerBack.png | Bin 34435 -> 0 bytes .../Themes/Styles/Base/ComboBoxBaseStyle.xaml | 1 - .../Styles/Base/DatePickerBaseStyle.xaml | 1 - .../Styles/Base/NumericUpDownBaseStyle.xaml | 60 +++ .../Styles/Base/PasswordBoxBaseStyle.xaml | 1 - .../Themes/Styles/Base/TextBoxBaseStyle.xaml | 1 - .../Styles/Base/TimePickerBaseStyle.xaml | 1 - .../Styles/Base/ToggleButtonBaseStyle.xaml | 3 - HandyControl/Themes/Styles/Border.xaml | 4 +- HandyControl/Themes/Styles/Button.xaml | 4 +- HandyControl/Themes/Styles/NumericUpDown.xaml | 13 + HandyControl/Themes/Styles/Style.xaml | 1 + HandyControl/Themes/Styles/Window.xaml | 79 ++++ HandyControlDemo/Data/MessageToken.cs | 2 + HandyControlDemo/Data/MessageToken.tt | 3 +- HandyControlDemo/HandyControlDemo.csproj | 7 + HandyControlDemo/Properties/AssemblyInfo.cs | 4 +- .../Properties/Langs/Lang.Designer.cs | 9 + .../Properties/Langs/Lang.en.resx | 3 + HandyControlDemo/Properties/Langs/Lang.resx | 3 + .../Controls/NumericUpDownDemoCtl.xaml | 11 + .../Controls/NumericUpDownDemoCtl.xaml.cs | 11 + .../UserControl/Main/LeftMainContent.xaml | 39 +- 37 files changed, 712 insertions(+), 965 deletions(-) delete mode 100644 HandyControl/Controls/Info/InfoControl.cs delete mode 100644 HandyControl/Controls/Info/InfoNumericUpDown.xaml delete mode 100644 HandyControl/Controls/Info/InfoNumericUpDown.xaml.cs delete mode 100644 HandyControl/Controls/Info/InfoTextBox.xaml delete mode 100644 HandyControl/Controls/Info/InfoTextBox.xaml.cs create mode 100644 HandyControl/Controls/NumericUpDown.cs rename HandyControl/Controls/Window/{ImageBrowser.xaml.cs => ImageBrowser.cs} (73%) delete mode 100644 HandyControl/Controls/Window/ImageBrowser.xaml delete mode 100644 HandyControl/Resources/colorPickerBack.png create mode 100644 HandyControl/Themes/Styles/Base/NumericUpDownBaseStyle.xaml create mode 100644 HandyControl/Themes/Styles/NumericUpDown.xaml create mode 100644 HandyControlDemo/UserControl/Controls/NumericUpDownDemoCtl.xaml create mode 100644 HandyControlDemo/UserControl/Controls/NumericUpDownDemoCtl.xaml.cs diff --git a/HandyControl/Controls/Info/InfoControl.cs b/HandyControl/Controls/Info/InfoControl.cs deleted file mode 100644 index 2b7eace3..00000000 --- a/HandyControl/Controls/Info/InfoControl.cs +++ /dev/null @@ -1,374 +0,0 @@ -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Media.Animation; -using HandyControl.Data.Enum; -using HandyControl.Tools; -using HandyControl.Tools.Converter; -using HandyControl.Tools.Extension; - -// ReSharper disable once CheckNamespace -namespace HandyControl.Controls -{ - internal abstract class InfoControl : UserControl - { - private bool _isFocused; - - protected TextBlock ErrorTextBlock; - - protected TextBox ContentTextBox; - - protected StackPanel TitleStackPanel; - - /// - /// 标题 - /// - public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( - "Title", typeof(string), typeof(InfoControl), new PropertyMetadata(default(string))); - - /// - /// 标题 - /// - public string Title - { - get => (string)GetValue(TitleProperty); - set => SetValue(TitleProperty, value); - } - - /// - /// 文本 - /// - public static readonly DependencyProperty TextProperty = DependencyProperty.Register( - "Text", typeof(string), typeof(InfoControl), new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); - - /// - /// 文本 - /// - public string Text - { - get => (string)GetValue(TextProperty); - set => SetValue(TextProperty, value); - } - - /// - /// 是否为必填项 - /// - public static readonly DependencyProperty IsNeedlyProperty = DependencyProperty.Register( - "IsNeedly", typeof(bool), typeof(InfoControl), new PropertyMetadata(true)); - - /// - /// 是否为必填项 - /// - public bool IsNeedly - { - get => (bool)GetValue(IsNeedlyProperty); - set => SetValue(IsNeedlyProperty, value); - } - - /// - /// 占位符 - /// - public static readonly DependencyProperty PlaceHolderProperty = DependencyProperty.Register( - "PlaceHolder", typeof(string), typeof(InfoControl), new PropertyMetadata(default(string))); - - /// - /// 占位符 - /// - public string PlaceHolder - { - get => (string)GetValue(PlaceHolderProperty); - set => SetValue(PlaceHolderProperty, value); - } - - /// - /// 错误信息 - /// - public static readonly DependencyProperty ErrorStrProperty = DependencyProperty.Register( - "ErrorStr", typeof(string), typeof(InfoControl), new PropertyMetadata(default(string))); - - /// - /// 错误信息 - /// - public string ErrorStr - { - get => (string)GetValue(ErrorStrProperty); - set => SetValue(ErrorStrProperty, value); - } - - /// - /// 控件是否包含错误 - /// - public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register( - "IsError", typeof(bool), typeof(InfoControl), new PropertyMetadata(default(bool))); - - /// - /// 控件是否包含错误 - /// - public bool IsError - { - get => (bool)GetValue(IsErrorProperty); - set => SetValue(IsErrorProperty, value); - } - - /// - /// 标题宽度 - /// - public static readonly DependencyProperty TitleWidthProperty = DependencyProperty.RegisterAttached( - "TitleWidth", typeof(GridLength), typeof(InfoControl), - new FrameworkPropertyMetadata(GridLength.Auto, FrameworkPropertyMetadataOptions.Inherits)); - - /// - /// 设置标题宽度 - /// - public static void SetTitleWidth(DependencyObject element, GridLength value) - { - element.SetValue(TitleWidthProperty, value); - } - - /// - /// 标题宽度 - /// - public static GridLength GetTitleWidth(DependencyObject element) - { - return (GridLength)element.GetValue(TitleWidthProperty); - } - - /// - /// 标题宽度 - /// - public GridLength TitleWidth - { - get => (GridLength)GetValue(TitleWidthProperty); - set => SetValue(TitleWidthProperty, value); - } - - /// - /// 标题对齐方式 - /// - public static readonly DependencyProperty TitleAlignmentProperty = DependencyProperty.Register( - "TitleAlignment", typeof(TitleAlignment), typeof(InfoControl), new PropertyMetadata(TitleAlignment.Left, - (o, args) => - { - var ctl = (InfoControl)o; - var v = (TitleAlignment)args.NewValue; - if (v == TitleAlignment.Left) - { - Grid.SetColumn(ctl.TitleStackPanel, 0); - Grid.SetRow(ctl.TitleStackPanel, 1); - ctl.HorizontalAlignment = HorizontalAlignment.Right; - ctl.Height = ctl.MaxHeight; - } - else - { - Grid.SetColumn(ctl.TitleStackPanel, 1); - Grid.SetRow(ctl.TitleStackPanel, 0); - ctl.TitleStackPanel.HorizontalAlignment = HorizontalAlignment.Left; - ctl.TitleStackPanel.Margin = new Thickness(4, 0, 0, 4); - ctl.Height += 18; - } - })); - - /// - /// 标题对齐方式 - /// - public TitleAlignment TitleAlignment - { - get => (TitleAlignment)GetValue(TitleAlignmentProperty); - set => SetValue(TitleAlignmentProperty, value); - } - - /// - /// 文本的水平对齐方式 - /// - public static readonly DependencyProperty HorizontalTextAlignmentProperty = DependencyProperty.Register( - "HorizontalTextAlignment", typeof(HorizontalAlignment), typeof(InfoControl), new PropertyMetadata(HorizontalAlignment.Left)); - - /// - /// 文本的水平对齐方式 - /// - public HorizontalAlignment HorizontalTextAlignment - { - get => (HorizontalAlignment)GetValue(HorizontalTextAlignmentProperty); - set => SetValue(HorizontalTextAlignmentProperty, value); - } - - /// - /// 是否显示清除按钮 - /// - public static readonly DependencyProperty ShowClearButtonProperty = DependencyProperty.Register( - "ShowClearButton", typeof(bool), typeof(InfoControl), new PropertyMetadata(true, (o, args) => - { - var ctl = (InfoControl)o; - var v = (bool)args.NewValue; - if (!(ctl.FindName("ButtonClear") is Button button)) return; - BindingOperations.ClearBinding(button, VisibilityProperty); - button.IsEnabled = v; - if (v) - { - button.SetBinding(VisibilityProperty, new Binding("Text") - { - Source = ctl, - Converter = new String2VisibilityConverter() - }); - } - else - { - button.Collapse(); - } - })); - - /// - /// 是否显示清除按钮 - /// - public bool ShowClearButton - { - get => (bool)GetValue(ShowClearButtonProperty); - set => SetValue(ShowClearButtonProperty, value); - } - - /// - /// 是否显示小圆角 - /// - public static readonly DependencyProperty ShowSmallCornerRadiusProperty = DependencyProperty.Register( - "ShowSmallCornerRadius", typeof(bool), typeof(InfoControl), new PropertyMetadata(default(bool), (o, args) => - { - var ctl = (InfoControl)o; - var v = (bool)args.NewValue; - ctl.CornerRadius = v ? new CornerRadius(2, 2, 2, 2) : new CornerRadius(4, 4, 4, 4); - })); - - /// - /// 是否显示小圆角 - /// - public bool ShowSmallCornerRadius - { - get => (bool)GetValue(ShowSmallCornerRadiusProperty); - set => SetValue(ShowSmallCornerRadiusProperty, value); - } - - /// - /// 圆角 - /// - protected static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register( - "CornerRadius", typeof(CornerRadius), typeof(InfoControl), new PropertyMetadata(new CornerRadius(4, 4, 4, 4))); - - /// - /// 圆角 - /// - protected CornerRadius CornerRadius - { - get => (CornerRadius)GetValue(CornerRadiusProperty); - set => SetValue(CornerRadiusProperty, value); - } - - /// - /// 文本内边距 - /// - public static readonly DependencyProperty TextPaddingProperty = DependencyProperty.Register( - "TextPadding", typeof(Thickness), typeof(InfoControl), new PropertyMetadata(new Thickness(6, 0, 0, 0))); - - /// - /// 文本内边距 - /// - public Thickness TextPadding - { - get => (Thickness)GetValue(TextPaddingProperty); - set => SetValue(TextPaddingProperty, value); - } - - /// - /// 更新状态 - /// - public virtual void Update() - { - if (!IsError) - { - if (!_isFocused) - { - (TryFindResource("Storyboard2") as Storyboard)?.Begin(); - } - else - { - (TryFindResource("Storyboard3") as Storyboard)?.Begin(); - } - ErrorTextBlock.BeginAnimation(MarginProperty, AnimationHelper.CreateAnimation(new Thickness(4, 0, 0, 1))); - return; - } - (TryFindResource("Storyboard4") as Storyboard)?.Begin(); - ErrorTextBlock.BeginAnimation(MarginProperty, AnimationHelper.CreateAnimation(new Thickness(4, 0, 0, -ErrorTextBlock.ActualHeight - 2))); - } - - protected virtual void InputBox_OnLostFocus(object sender, RoutedEventArgs e) - { - _isFocused = false; - CheckInfo(); - } - - protected virtual void InputBox_OnGotFocus(object sender, RoutedEventArgs e) - { - _isFocused = true; - if (!IsError) - { - (TryFindResource("Storyboard3") as Storyboard)?.Begin(); - } - } - - protected virtual void InputBox_OnMouseEnter(object sender, MouseEventArgs e) - { - if (!IsError && !ContentTextBox.IsFocused) - { - (TryFindResource("Storyboard1") as Storyboard)?.Begin(); - } - } - - protected virtual void InputBox_OnMouseLeave(object sender, MouseEventArgs e) - { - if (!IsError && !ContentTextBox.IsFocused) - { - (TryFindResource("Storyboard2") as Storyboard)?.Begin(); - } - } - - protected virtual void InputBox_OnTextChanged(object sender, TextChangedEventArgs e) => CheckInfo(); - - protected virtual void ButtonClear_OnClick(object sender, RoutedEventArgs e) => Text = string.Empty; - - /// - /// 文本类型 - /// - public TextType TextType { get; set; } - - /// - /// 正则字符串(当文本类型为Common时,此属性才生效) - /// - public string RegularStr { get; set; } - - /// - /// 用于监测数据的正确性 - /// - /// - public virtual bool CheckInfo() - { - bool result; - if (TextType == TextType.Common) - { - if (string.IsNullOrEmpty(RegularStr)) - { - result = !IsNeedly || !string.IsNullOrEmpty(Text); - } - else - { - result = Text.IsKindOf(RegularStr); - } - } - else - { - result = Text.IsKindOf(TextType); - } - IsError = !result; - Update(); - return result; - } - } -} \ No newline at end of file diff --git a/HandyControl/Controls/Info/InfoNumericUpDown.xaml b/HandyControl/Controls/Info/InfoNumericUpDown.xaml deleted file mode 100644 index 65c786c3..00000000 --- a/HandyControl/Controls/Info/InfoNumericUpDown.xaml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -