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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -