Daily maintenance 19-01-18

This commit is contained in:
NaBian committed 2019-01-18 15:50:47 +08:00
1 parent 741f8788d9
commit fcc7c3966a
3 files changed
+109 -72

No files matched your search

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