diff --git a/HandyControl/Controls/Input/SearchBar.cs b/HandyControl/Controls/Input/SearchBar.cs index 864d3b39..d37ab5b1 100644 --- a/HandyControl/Controls/Input/SearchBar.cs +++ b/HandyControl/Controls/Input/SearchBar.cs @@ -20,17 +20,8 @@ namespace HandyControl.Controls public SearchBar() { - CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) => - { - _textBox.Text = string.Empty; - })); - CommandBindings.Add(new CommandBinding(ControlCommands.Search, (s, e) => - { - RaiseEvent(new FunctionEventArgs(SearchStartedEvent, this) - { - Info = Text - }); - })); + CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) => _textBox.Text = string.Empty)); + CommandBindings.Add(new CommandBinding(ControlCommands.Search, (s, e) => OnSearchStarted())); } public static readonly RoutedEvent SearchStartedEvent = @@ -70,21 +61,33 @@ namespace HandyControl.Controls { if (e.Key == Key.Enter) { - RaiseEvent(new FunctionEventArgs(SearchStartedEvent, this) - { - Info = Text - }); + OnSearchStarted(); } } - private void TextBox_TextChanged(object sender, TextChangedEventArgs e) => VerifyData(); + private void TextBox_TextChanged(object sender, TextChangedEventArgs e) + { + if (IsRealTime) + { + OnSearchStarted(); + } + VerifyData(); + } + + private void OnSearchStarted() + { + RaiseEvent(new FunctionEventArgs(SearchStartedEvent, this) + { + Info = Text + }); + } public static readonly DependencyProperty TextProperty = DependencyProperty.Register( "Text", typeof(string), typeof(SearchBar), new PropertyMetadata(default(string))); public string Text { - get => (string) GetValue(TextProperty); + get => (string)GetValue(TextProperty); set => SetValue(TextProperty, value); } @@ -120,7 +123,7 @@ namespace HandyControl.Controls public TextType TextType { - get => (TextType) GetValue(TextTypeProperty); + get => (TextType)GetValue(TextTypeProperty); set => SetValue(TextTypeProperty, value); } @@ -136,6 +139,21 @@ namespace HandyControl.Controls set => SetValue(ShowClearButtonProperty, value); } + /// + /// 是否实时搜索 + /// + public static readonly DependencyProperty IsRealTimeProperty = DependencyProperty.Register( + "IsRealTime", typeof(bool), typeof(SearchBar), new PropertyMetadata(ValueBoxes.FalseBox)); + + /// + /// 是否实时搜索 + /// + public bool IsRealTime + { + get => (bool)GetValue(IsRealTimeProperty); + set => SetValue(IsRealTimeProperty, value); + } + public virtual bool VerifyData() { OperationResult result; diff --git a/HandyControl/Controls/Other/Growl.cs b/HandyControl/Controls/Other/Growl.cs index b5002547..6016ce5e 100644 --- a/HandyControl/Controls/Other/Growl.cs +++ b/HandyControl/Controls/Other/Growl.cs @@ -41,6 +41,23 @@ namespace HandyControl.Controls private bool _staysOpen; + private int _waitTime = 6; + + /// + /// 消息容器 + /// + public static Panel GrowlPanel { get; set; } + + /// + /// 计数 + /// + private int _tickCount; + + /// + /// 关闭计时器 + /// + private DispatcherTimer _timerClose; + #endregion Data public Growl() @@ -74,26 +91,6 @@ namespace HandyControl.Controls if (_panelMore == null || _gridMain == null || _buttonClose == null) throw new Exception(); } - /// - /// 最大计数 - /// - private const int MaxTickCount = 6; - - /// - /// 消息容器 - /// - private static Panel GrowlPanel; - - /// - /// 计数 - /// - private int _tickCount; - - /// - /// 关闭计时器 - /// - private DispatcherTimer _timerClose; - private Func ActionBeforeClose { get; set; } internal static readonly DependencyProperty CancelStrProperty = DependencyProperty.Register( @@ -131,11 +128,11 @@ namespace HandyControl.Controls public static void SetGrowlParent(DependencyObject element, bool value) => element.SetValue(GrowlParentProperty, value); - public static bool GetGrowlParent(DependencyObject element) => (bool) element.GetValue(GrowlParentProperty); + public static bool GetGrowlParent(DependencyObject element) => (bool)element.GetValue(GrowlParentProperty); public InfoType Type { - get => (InfoType) GetValue(TypeProperty); + get => (InfoType)GetValue(TypeProperty); set => SetValue(TypeProperty, value); } @@ -199,7 +196,7 @@ namespace HandyControl.Controls } _tickCount++; - if (_tickCount >= MaxTickCount) Close(); + if (_tickCount >= _waitTime) Close(); }; _timerClose.Start(); } @@ -276,7 +273,8 @@ namespace HandyControl.Controls ShowDateTime = growlInfo.ShowDateTime, ConfirmStr = growlInfo.ConfirmStr, CancelStr = growlInfo.CancelStr, - Type = growlInfo.Type + Type = growlInfo.Type, + _waitTime = Math.Max(growlInfo.WaitTime, 2) }; GrowlPanel.Children.Insert(0, ctl); } @@ -297,9 +295,12 @@ namespace HandyControl.Controls public static void Success(GrowlInfo growlInfo) { if (growlInfo == null) throw new ArgumentNullException(nameof(growlInfo)); - growlInfo.IconKey = ResourceToken.SuccessGeometry; - growlInfo.IconBrushKey = ResourceToken.SuccessBrush; - growlInfo.Type = InfoType.Success; + if (!growlInfo.IsCustom) + { + growlInfo.IconKey = ResourceToken.SuccessGeometry; + growlInfo.IconBrushKey = ResourceToken.SuccessBrush; + growlInfo.Type = InfoType.Success; + } Show(growlInfo); } @@ -319,9 +320,12 @@ namespace HandyControl.Controls public static void Info(GrowlInfo growlInfo) { if (growlInfo == null) throw new ArgumentNullException(nameof(growlInfo)); - growlInfo.IconKey = ResourceToken.InfoGeometry; - growlInfo.IconBrushKey = ResourceToken.InfoBrush; - growlInfo.Type = InfoType.Info; + if (!growlInfo.IsCustom) + { + growlInfo.IconKey = ResourceToken.InfoGeometry; + growlInfo.IconBrushKey = ResourceToken.InfoBrush; + growlInfo.Type = InfoType.Info; + } Show(growlInfo); } @@ -341,9 +345,12 @@ namespace HandyControl.Controls public static void Warning(GrowlInfo growlInfo) { if (growlInfo == null) throw new ArgumentNullException(nameof(growlInfo)); - growlInfo.IconKey = ResourceToken.WarningGeometry; - growlInfo.IconBrushKey = ResourceToken.WarningBrush; - growlInfo.Type = InfoType.Warning; + if (!growlInfo.IsCustom) + { + growlInfo.IconKey = ResourceToken.WarningGeometry; + growlInfo.IconBrushKey = ResourceToken.WarningBrush; + growlInfo.Type = InfoType.Warning; + } Show(growlInfo); } @@ -363,10 +370,13 @@ namespace HandyControl.Controls public static void Error(GrowlInfo growlInfo) { if (growlInfo == null) throw new ArgumentNullException(nameof(growlInfo)); - growlInfo.IconKey = ResourceToken.ErrorGeometry; - growlInfo.IconBrushKey = ResourceToken.DangerBrush; - growlInfo.StaysOpen = true; - growlInfo.Type = InfoType.Error; + if (!growlInfo.IsCustom) + { + growlInfo.IconKey = ResourceToken.ErrorGeometry; + growlInfo.IconBrushKey = ResourceToken.DangerBrush; + growlInfo.StaysOpen = true; + growlInfo.Type = InfoType.Error; + } Show(growlInfo); } @@ -386,13 +396,15 @@ namespace HandyControl.Controls public static void Fatal(GrowlInfo growlInfo) { if (growlInfo == null) throw new ArgumentNullException(nameof(growlInfo)); - growlInfo.IconKey = ResourceToken.FatalGeometry; - growlInfo.IconBrushKey = ResourceToken.PrimaryTextBrush; - growlInfo.StaysOpen = true; - growlInfo.ShowCloseButton = false; - growlInfo.Type = InfoType.Fatal; - // ReSharper disable once PossibleNullReferenceException - GrowlPanel.ContextMenu.Opacity = 0; + if (!growlInfo.IsCustom) + { + growlInfo.IconKey = ResourceToken.FatalGeometry; + growlInfo.IconBrushKey = ResourceToken.PrimaryTextBrush; + growlInfo.StaysOpen = true; + growlInfo.ShowCloseButton = false; + growlInfo.Type = InfoType.Fatal; + if (GrowlPanel.ContextMenu != null) GrowlPanel.ContextMenu.Opacity = 0; + } Show(growlInfo); } @@ -414,11 +426,14 @@ namespace HandyControl.Controls public static void Ask(GrowlInfo growlInfo) { if (growlInfo == null) throw new ArgumentNullException(nameof(growlInfo)); - growlInfo.IconKey = ResourceToken.AskGeometry; - growlInfo.IconBrushKey = ResourceToken.AccentBrush; - growlInfo.StaysOpen = true; - growlInfo.ShowCloseButton = false; - growlInfo.Type = InfoType.Ask; + if (!growlInfo.IsCustom) + { + growlInfo.IconKey = ResourceToken.AskGeometry; + growlInfo.IconBrushKey = ResourceToken.AccentBrush; + growlInfo.StaysOpen = true; + growlInfo.ShowCloseButton = false; + growlInfo.Type = InfoType.Ask; + } Show(growlInfo); } diff --git a/HandyControl/Data/GrowlInfo.cs b/HandyControl/Data/GrowlInfo.cs index 9c952a8a..cffc7317 100644 --- a/HandyControl/Data/GrowlInfo.cs +++ b/HandyControl/Data/GrowlInfo.cs @@ -8,20 +8,24 @@ namespace HandyControl.Data public bool ShowDateTime { get; set; } = true; + public int WaitTime { get; set; } = 6; + public string CancelStr { get; set; } = Properties.Langs.Lang.Cancel; public string ConfirmStr { get; set; } = Properties.Langs.Lang.Confirm; public Func ActionBeforeClose { get; set; } - internal InfoType Type { get; set; } + public bool StaysOpen { get; set; } - internal string IconKey { get; set; } + public bool IsCustom { get; set; } - internal string IconBrushKey { get; set; } + public InfoType Type { get; set; } - internal bool StaysOpen { get; set; } + public string IconKey { get; set; } - internal bool ShowCloseButton { get; set; } = true; + public string IconBrushKey { get; set; } + + public bool ShowCloseButton { get; set; } = true; } } \ No newline at end of file