From 30575922fe60ce5bd412bfdf5c5e773455547de9 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sun, 24 Mar 2019 01:14:07 +0800 Subject: [PATCH 1/4] fixed a bug of messagebox --- HandyControl/Controls/Window/MessageBox.cs | 95 +++++++------- HandyControl/Controls/Window/Window.cs | 93 +++++--------- HandyControl/Themes/Styles/MessageBox.xaml | 120 ++++++++++++++---- HandyControl/Themes/Styles/Window.xaml | 15 ++- .../Resources/Themes/Styles/Style.xaml | 27 +--- 5 files changed, 189 insertions(+), 161 deletions(-) diff --git a/HandyControl/Controls/Window/MessageBox.cs b/HandyControl/Controls/Window/MessageBox.cs index 36007596..c6c6cd85 100644 --- a/HandyControl/Controls/Window/MessageBox.cs +++ b/HandyControl/Controls/Window/MessageBox.cs @@ -1,14 +1,10 @@ -using System; -using System.ComponentModel; +using System.ComponentModel; using System.Windows; -using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; -using System.Windows.Shapes; using HandyControl.Data; using HandyControl.Interactivity; using HandyControl.Tools; -using HandyControl.Tools.Extension; namespace HandyControl.Controls { @@ -17,14 +13,6 @@ namespace HandyControl.Controls /// public sealed class MessageBox : Window { - #region Constants - - private const string ElementImage = "PART_Image"; - - private const string ElementMessage = "PART_Message"; - - #endregion Constants - private MessageBoxResult _messageBoxResult = MessageBoxResult.Cancel; private bool _showOk; @@ -35,13 +23,41 @@ namespace HandyControl.Controls private bool _showNo; - private string _message; + public static readonly DependencyProperty MessageProperty = DependencyProperty.Register( + "Message", typeof(string), typeof(MessageBox), new PropertyMetadata(default(string))); - private Geometry _image; + public string Message + { + get => (string) GetValue(MessageProperty); + set => SetValue(MessageProperty, value); + } - private Brush _imageBrush; + public static readonly DependencyProperty ImageProperty = DependencyProperty.Register( + "Image", typeof(Geometry), typeof(MessageBox), new PropertyMetadata(default(Geometry))); - private bool _showImage; + public Geometry Image + { + get => (Geometry) GetValue(ImageProperty); + set => SetValue(ImageProperty, value); + } + + public static readonly DependencyProperty ImageBrushProperty = DependencyProperty.Register( + "ImageBrush", typeof(Brush), typeof(MessageBox), new PropertyMetadata(default(Brush))); + + public Brush ImageBrush + { + get => (Brush) GetValue(ImageBrushProperty); + set => SetValue(ImageBrushProperty, value); + } + + public static readonly DependencyProperty ShowImageProperty = DependencyProperty.Register( + "ShowImage", typeof(bool), typeof(MessageBox), new PropertyMetadata(ValueBoxes.FalseBox)); + + public bool ShowImage + { + get => (bool) GetValue(ShowImageProperty); + set => SetValue(ShowImageProperty, value); + } private MessageBox() { @@ -67,23 +83,6 @@ namespace HandyControl.Controls }, (s, e) => e.CanExecute = _showNo)); } - protected override void OnSourceInitialized(EventArgs e) - { - base.OnSourceInitialized(e); - - if (LogicalTreeHelper.FindLogicalNode(this, ElementMessage) is TextBlock message) message.Text = _message; - - if (_showImage) - { - if (LogicalTreeHelper.FindLogicalNode(this, ElementImage) is Path image) - { - image.Data = _image; - image.Fill = _imageBrush; - image.Show(); - } - } - } - /// /// 成功 /// @@ -96,9 +95,9 @@ namespace HandyControl.Controls { messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK); SetButtonStatus(messageBox, MessageBoxButton.OK); - messageBox._showImage = true; - messageBox._image = ResourceHelper.GetResource(ResourceToken.SuccessGeometry); - messageBox._imageBrush = ResourceHelper.GetResource(ResourceToken.SuccessBrush); + messageBox.ShowImage = true; + messageBox.Image = ResourceHelper.GetResource(ResourceToken.SuccessGeometry); + messageBox.ImageBrush = ResourceHelper.GetResource(ResourceToken.SuccessBrush); messageBox.ShowDialog(); }); @@ -174,9 +173,9 @@ namespace HandyControl.Controls { messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK); SetButtonStatus(messageBox, MessageBoxButton.OK); - messageBox._showImage = true; - messageBox._image = ResourceHelper.GetResource(ResourceToken.FatalGeometry); - messageBox._imageBrush = ResourceHelper.GetResource(ResourceToken.PrimaryTextBrush); + messageBox.ShowImage = true; + messageBox.Image = ResourceHelper.GetResource(ResourceToken.FatalGeometry); + messageBox.ImageBrush = ResourceHelper.GetResource(ResourceToken.PrimaryTextBrush); messageBox.ShowDialog(); }); @@ -217,9 +216,9 @@ namespace HandyControl.Controls if (!string.IsNullOrEmpty(info.IconKey)) { - messageBox._showImage = true; - messageBox._image = ResourceHelper.GetResource(info.IconKey); - messageBox._imageBrush = ResourceHelper.GetResource(info.IconBrushKey); + messageBox.ShowImage = true; + messageBox.Image = ResourceHelper.GetResource(info.IconKey); + messageBox.ImageBrush = ResourceHelper.GetResource(info.IconBrushKey); } messageBox.Style = info.Style; @@ -293,9 +292,9 @@ namespace HandyControl.Controls return new MessageBox { - _message = messageBoxText, + Message = messageBoxText, Owner = ownerWindow, - WindowStartupLocation = ownerIsNull ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner, + WindowStartupLocation = WindowStartupLocation.CenterScreen, ShowTitle = true, Title = caption ?? string.Empty, Topmost = ownerIsNull, @@ -352,9 +351,9 @@ namespace HandyControl.Controls } if (string.IsNullOrEmpty(iconKey)) return; - messageBox._showImage = true; - messageBox._image = ResourceHelper.GetResource(iconKey); - messageBox._imageBrush = ResourceHelper.GetResource(iconBrushKey); + messageBox.ShowImage = true; + messageBox.Image = ResourceHelper.GetResource(iconKey); + messageBox.ImageBrush = ResourceHelper.GetResource(iconBrushKey); } private static bool IsValidMessageBoxButton(MessageBoxButton value) diff --git a/HandyControl/Controls/Window/Window.cs b/HandyControl/Controls/Window/Window.cs index ee8d9fc1..be713cfb 100644 --- a/HandyControl/Controls/Window/Window.cs +++ b/HandyControl/Controls/Window/Window.cs @@ -1,11 +1,9 @@ using System; using System.Windows; -using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; using HandyControl.Data; -using HandyControl.Tools; using HandyControl.Tools.Extension; #if netle40 using Microsoft.Windows.Shell; @@ -81,14 +79,14 @@ namespace HandyControl.Controls private bool _isFullScreen; + private Thickness _actualBorderThickness; + private UIElement _nonClientArea; private bool _showNonClientArea = true; private double _tempNonClientAreaHeight; - private Thickness _tempThickness; - private WindowState _tempWindowState; private WindowStyle _tempWindowStyle; @@ -106,31 +104,7 @@ namespace HandyControl.Controls new Binding(NonClientAreaHeightProperty.Name) {Source = this}); WindowChrome.SetWindowChrome(this, chrome); - Loaded += delegate - { - _tempThickness = BorderThickness; - if (WindowState == WindowState.Maximized) - { - BorderThickness = new Thickness(); - } - - CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, - (s, e) => WindowState = WindowState.Minimized)); - CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, - (s, e) => WindowState = WindowState.Maximized)); - CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, - (s, e) => WindowState = WindowState.Normal)); - CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (s, e) => Close())); - CommandBindings.Add(new CommandBinding(SystemCommands.ShowSystemMenuCommand, ShowSystemMenu)); - - _tempNonClientAreaHeight = NonClientAreaHeight; - _tempWindowState = WindowState; - _tempWindowStyle = WindowStyle; - _tempResizeMode = ResizeMode; - - SwitchIsFullScreen(_isFullScreen); - SwitchShowNonClientArea(_showNonClientArea); - }; + Loaded += (s, e) => OnLoaded(e); } public Brush CloseButtonBackground @@ -317,15 +291,34 @@ namespace HandyControl.Controls } else if (WindowState == WindowState.Normal) { - BorderThickness = _tempThickness; + BorderThickness = _actualBorderThickness; } } - public override void OnApplyTemplate() + protected void OnLoaded(RoutedEventArgs args) { - base.OnApplyTemplate(); + _actualBorderThickness = BorderThickness; + if (WindowState == WindowState.Maximized) + { + BorderThickness = new Thickness(); + } - _nonClientArea = GetTemplateChild(ElementNonClientArea) as UIElement; + CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, + (s, e) => WindowState = WindowState.Minimized)); + CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, + (s, e) => WindowState = WindowState.Maximized)); + CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, + (s, e) => WindowState = WindowState.Normal)); + CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (s, e) => Close())); + CommandBindings.Add(new CommandBinding(SystemCommands.ShowSystemMenuCommand, ShowSystemMenu)); + + _tempNonClientAreaHeight = NonClientAreaHeight; + _tempWindowState = WindowState; + _tempWindowStyle = WindowStyle; + _tempResizeMode = ResizeMode; + + SwitchIsFullScreen(_isFullScreen); + SwitchShowNonClientArea(_showNonClientArea); if (SizeToContent != SizeToContent.WidthAndHeight) return; @@ -334,11 +327,18 @@ namespace HandyControl.Controls Dispatcher.BeginInvoke(new Action(() => { SizeToContent = SizeToContent.WidthAndHeight; })); } + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + _nonClientArea = GetTemplateChild(ElementNonClientArea) as UIElement; + } + private void ShowSystemMenu(object sender, ExecutedRoutedEventArgs e) { var point = WindowState == WindowState.Maximized - ? new Point(0, 28) - : new Point(Left, Top + 28); + ? new Point(0, NonClientAreaHeight) + : new Point(Left, Top + NonClientAreaHeight); SystemCommands.ShowSystemMenu(this, point); } @@ -348,28 +348,5 @@ namespace HandyControl.Controls if (SizeToContent == SizeToContent.WidthAndHeight) InvalidateMeasure(); } - - /// - /// 获取自定义窗口 - /// - /// - public static Window GetCustomWindow(FrameworkElement content) - { - var window = new Window - { - Style = ResourceHelper.GetResource - \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Window.xaml b/HandyControl/Themes/Styles/Window.xaml index c31413e4..c93bc3f5 100644 --- a/HandyControl/Themes/Styles/Window.xaml +++ b/HandyControl/Themes/Styles/Window.xaml @@ -46,25 +46,26 @@ - - \ No newline at end of file From a92a3ce82dade7d93bb9702c07a1bb5623aa82bf Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sun, 24 Mar 2019 14:01:17 +0800 Subject: [PATCH 2/4] Update MessageBox.cs add message replication --- HandyControl/Controls/Window/MessageBox.cs | 49 +++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/HandyControl/Controls/Window/MessageBox.cs b/HandyControl/Controls/Window/MessageBox.cs index c6c6cd85..67342fd7 100644 --- a/HandyControl/Controls/Window/MessageBox.cs +++ b/HandyControl/Controls/Window/MessageBox.cs @@ -1,4 +1,6 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; +using System.Text; using System.Windows; using System.Windows.Input; using System.Windows.Media; @@ -83,6 +85,51 @@ namespace HandyControl.Controls }, (s, e) => e.CanExecute = _showNo)); } + protected override void OnPreviewKeyDown(KeyEventArgs e) + { + base.OnPreviewKeyDown(e); + + if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.C) + { + var builder = new StringBuilder(); + var line = new string('-', 27); + builder.Append(line); + builder.Append(Environment.NewLine); + builder.Append(Title); + builder.Append(Environment.NewLine); + builder.Append(line); + builder.Append(Environment.NewLine); + builder.Append(Message); + builder.Append(Environment.NewLine); + builder.Append(line); + builder.Append(Environment.NewLine); + if (_showOk) + { + builder.Append(Properties.Langs.Lang.Confirm); + builder.Append(" "); + } + if (_showYes) + { + builder.Append(Properties.Langs.Lang.Yes); + builder.Append(" "); + } + if (_showNo) + { + builder.Append(Properties.Langs.Lang.No); + builder.Append(" "); + } + if (_showCancel) + { + builder.Append(Properties.Langs.Lang.Cancel); + builder.Append(" "); + } + builder.Append(Environment.NewLine); + builder.Append(line); + builder.Append(Environment.NewLine); + Clipboard.SetText(builder.ToString()); + } + } + /// /// 成功 /// From 7c331c1e607bb07fc97f01b557f9ee1c68953f2e Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sun, 24 Mar 2019 15:22:39 +0800 Subject: [PATCH 3/4] SearchBar command support --- HandyControl/Controls/Input/SearchBar.cs | 61 ++++++++++++++++++- HandyControlDemo/HandyControlDemo.csproj | 1 + .../Controls/SearchBarDemoCtl.xaml | 3 +- .../Controls/SearchBarDemoViewModel.cs | 18 ++++++ .../ViewModel/ViewModelLocator.cs | 3 + 5 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 HandyControlDemo/ViewModel/Controls/SearchBarDemoViewModel.cs diff --git a/HandyControl/Controls/Input/SearchBar.cs b/HandyControl/Controls/Input/SearchBar.cs index d34a3557..3b13e84e 100644 --- a/HandyControl/Controls/Input/SearchBar.cs +++ b/HandyControl/Controls/Input/SearchBar.cs @@ -7,7 +7,7 @@ using HandyControl.Interactivity; namespace HandyControl.Controls { - public class SearchBar : TextBox + public class SearchBar : TextBox, ICommandSource { public SearchBar() { @@ -51,6 +51,16 @@ namespace HandyControl.Controls { Info = Text }); + + if (Command == null) return; + if (Command is RoutedCommand command) + { + command.Execute(CommandParameter, CommandTarget); + } + else + { + Command.Execute(CommandParameter); + } } /// @@ -67,5 +77,54 @@ namespace HandyControl.Controls get => (bool)GetValue(IsRealTimeProperty); set => SetValue(IsRealTimeProperty, value); } + + public static readonly DependencyProperty CommandProperty = DependencyProperty.Register( + "Command", typeof(ICommand), typeof(SearchBar), new PropertyMetadata(default(ICommand), OnCommandChanged)); + + private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var ctl = (SearchBar)d; + if (e.OldValue is ICommand oldCommand) + { + oldCommand.CanExecuteChanged -= ctl.CanExecuteChanged; + } + if (e.NewValue is ICommand newCommand) + { + newCommand.CanExecuteChanged += ctl.CanExecuteChanged; + } + } + + public ICommand Command + { + get => (ICommand) GetValue(CommandProperty); + set => SetValue(CommandProperty, value); + } + + public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register( + "CommandParameter", typeof(object), typeof(SearchBar), new PropertyMetadata(default(object))); + + public object CommandParameter + { + get => GetValue(CommandParameterProperty); + set => SetValue(CommandParameterProperty, value); + } + + public static readonly DependencyProperty CommandTargetProperty = DependencyProperty.Register( + "CommandTarget", typeof(IInputElement), typeof(SearchBar), new PropertyMetadata(default(IInputElement))); + + public IInputElement CommandTarget + { + get => (IInputElement) GetValue(CommandTargetProperty); + set => SetValue(CommandTargetProperty, value); + } + + private void CanExecuteChanged(object sender, EventArgs e) + { + if (Command == null) return; + + IsEnabled = Command is RoutedCommand command + ? command.CanExecute(CommandParameter, CommandTarget) + : Command.CanExecute(CommandParameter); + } } } diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj index 3c727753..5a62c661 100644 --- a/HandyControlDemo/HandyControlDemo.csproj +++ b/HandyControlDemo/HandyControlDemo.csproj @@ -359,6 +359,7 @@ + diff --git a/HandyControlDemo/UserControl/Controls/SearchBarDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/SearchBarDemoCtl.xaml index 3159c30f..cc484896 100644 --- a/HandyControlDemo/UserControl/Controls/SearchBarDemoCtl.xaml +++ b/HandyControlDemo/UserControl/Controls/SearchBarDemoCtl.xaml @@ -3,11 +3,12 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl" xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs" + DataContext="{Binding SearchBarDemo,Source={StaticResource Locator}}" Background="{DynamicResource RegionBrush}"> - + diff --git a/HandyControlDemo/ViewModel/Controls/SearchBarDemoViewModel.cs b/HandyControlDemo/ViewModel/Controls/SearchBarDemoViewModel.cs new file mode 100644 index 00000000..75dccd5f --- /dev/null +++ b/HandyControlDemo/ViewModel/Controls/SearchBarDemoViewModel.cs @@ -0,0 +1,18 @@ +using System; +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Command; +using HandyControl.Controls; + +namespace HandyControlDemo.ViewModel +{ + public class SearchBarDemoViewModel : ViewModelBase + { + public RelayCommand SearchCmd => new Lazy>(() => + new RelayCommand(Search)).Value; + + private void Search(string key) + { + Growl.Info(key); + } + } +} \ No newline at end of file diff --git a/HandyControlDemo/ViewModel/ViewModelLocator.cs b/HandyControlDemo/ViewModel/ViewModelLocator.cs index 960bdef1..800ce4fe 100644 --- a/HandyControlDemo/ViewModel/ViewModelLocator.cs +++ b/HandyControlDemo/ViewModel/ViewModelLocator.cs @@ -25,6 +25,7 @@ namespace HandyControlDemo.ViewModel SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); } public static ViewModelLocator Instance => new Lazy(() => @@ -54,6 +55,8 @@ namespace HandyControlDemo.ViewModel public DialogDemoViewModel DialogDemo => ServiceLocator.Current.GetInstance(); + public SearchBarDemoViewModel SearchBarDemo => ServiceLocator.Current.GetInstance(); + #endregion } } \ No newline at end of file From 0cdb6d7543bacc925144322d366192e455c5d2f9 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sun, 24 Mar 2019 16:54:42 +0800 Subject: [PATCH 4/4] Growl multi-window support --- HandyControl/Controls/Attach/PanelElement.cs | 4 +- HandyControl/Controls/Other/Growl.cs | 48 +++++++++++-------- HandyControl/Data/ResourceToken.cs | 1 + .../Interactivity/BehaviorCollection.cs | 4 +- HandyControlDemo/HandyControlDemo.csproj | 7 +++ HandyControlDemo/MainWindow.xaml | 2 +- HandyControlDemo/MainWindow.xaml.cs | 19 +++++++- .../Properties/Langs/Lang.Designer.cs | 18 +++++++ .../Properties/Langs/Lang.en.resx | 6 +++ HandyControlDemo/Properties/Langs/Lang.resx | 6 +++ .../UserControl/Controls/GrowlDemoCtl.xaml | 21 ++++---- .../ViewModel/Controls/GrowlDemoViewModel.cs | 4 ++ HandyControlDemo/Window/GrowlDemoWindow.xaml | 29 +++++++++++ .../Window/GrowlDemoWindow.xaml.cs | 27 +++++++++++ 14 files changed, 160 insertions(+), 36 deletions(-) create mode 100644 HandyControlDemo/Window/GrowlDemoWindow.xaml create mode 100644 HandyControlDemo/Window/GrowlDemoWindow.xaml.cs diff --git a/HandyControl/Controls/Attach/PanelElement.cs b/HandyControl/Controls/Attach/PanelElement.cs index f1788378..05578452 100644 --- a/HandyControl/Controls/Attach/PanelElement.cs +++ b/HandyControl/Controls/Attach/PanelElement.cs @@ -15,12 +15,12 @@ namespace HandyControl.Controls { var collection = Interaction.GetBehaviors(panel); var oldBehavior = GetTempFluidMoveBehavior(panel); - collection.Remove(oldBehavior); + collection.ItemRemoved(oldBehavior); panel.SetCurrentValue(TempFluidMoveBehaviorProperty, DependencyProperty.UnsetValue); if (e.NewValue is FluidMoveBehavior behavior) { - collection.Add(behavior); + collection.ItemAdded(behavior); SetTempFluidMoveBehavior(panel, behavior); } } diff --git a/HandyControl/Controls/Other/Growl.cs b/HandyControl/Controls/Other/Growl.cs index f6ec5b4c..ed274460 100644 --- a/HandyControl/Controls/Other/Growl.cs +++ b/HandyControl/Controls/Other/Growl.cs @@ -4,7 +4,6 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; -using System.Windows.Media.Animation; using System.Windows.Threading; using HandyControl.Data; using HandyControl.Interactivity; @@ -43,11 +42,6 @@ namespace HandyControl.Controls private int _waitTime = 6; - /// - /// 消息容器 - /// - public static Panel GrowlPanel { get; set; } - /// /// 计数 /// @@ -65,14 +59,21 @@ namespace HandyControl.Controls CommandBindings.Add(new CommandBinding(ControlCommands.Close, ButtonClose_OnClick)); CommandBindings.Add(new CommandBinding(ControlCommands.Cancel, ButtonCancel_OnClick)); CommandBindings.Add(new CommandBinding(ControlCommands.Confirm, ButtonOk_OnClick)); - - MouseEnter += Growl_MouseEnter; - MouseLeave += Growl_MouseLeave; } - private void Growl_MouseLeave(object sender, MouseEventArgs e) => _buttonClose.Collapse(); + protected override void OnMouseEnter(MouseEventArgs e) + { + base.OnMouseEnter(e); - private void Growl_MouseEnter(object sender, MouseEventArgs e) => _buttonClose.Show(_showCloseButton); + _buttonClose.Show(_showCloseButton); + } + + protected override void OnMouseLeave(MouseEventArgs e) + { + base.OnMouseLeave(e); + + _buttonClose.Collapse(); + } public override void OnApplyTemplate() { @@ -93,6 +94,11 @@ namespace HandyControl.Controls private Func ActionBeforeClose { get; set; } + /// + /// 消息容器 + /// + public static Panel GrowlPanel { get; set; } + internal static readonly DependencyProperty CancelStrProperty = DependencyProperty.Register( "CancelStr", typeof(string), typeof(Growl), new PropertyMetadata(default(string))); @@ -120,7 +126,7 @@ namespace HandyControl.Controls public static readonly DependencyProperty GrowlParentProperty = DependencyProperty.RegisterAttached( "GrowlParent", typeof(bool), typeof(Growl), new PropertyMetadata(ValueBoxes.FalseBox, (o, args) => { - if (o is Panel panel) + if ((bool)args.NewValue && o is Panel panel) { SetGrowlPanel(panel); } @@ -226,14 +232,8 @@ namespace HandyControl.Controls menuItem } }; - var behavior = new FluidMoveBehavior - { - AppliesTo = FluidMoveScope.Children, - Duration = new Duration(TimeSpan.FromMilliseconds(400)), - EaseY = new PowerEase() - }; - var collection = Interaction.GetBehaviors(GrowlPanel); - collection.Add(behavior); + + PanelElement.SetFluidMoveBehavior(GrowlPanel, ResourceHelper.GetResource(ResourceToken.BehaviorXY400)); } private void Update() @@ -451,7 +451,13 @@ namespace HandyControl.Controls var transform = new TranslateTransform(); _gridMain.RenderTransform = transform; var animation = AnimationHelper.CreateAnimation(MaxWidth); - animation.Completed += delegate { GrowlPanel.Children.Remove(this); }; + animation.Completed += (s, e) => + { + if (Parent is Panel panel) + { + panel.Children.Remove(this); + } + }; transform.BeginAnimation(TranslateTransform.XProperty, animation); } diff --git a/HandyControl/Data/ResourceToken.cs b/HandyControl/Data/ResourceToken.cs index bba58672..a8ebcb90 100644 --- a/HandyControl/Data/ResourceToken.cs +++ b/HandyControl/Data/ResourceToken.cs @@ -64,5 +64,6 @@ internal const string TabItemCapsuleVerticalLast = nameof(TabItemCapsuleVerticalLast); + internal const string BehaviorXY400 = nameof(BehaviorXY400); } } \ No newline at end of file diff --git a/HandyControl/Interactivity/BehaviorCollection.cs b/HandyControl/Interactivity/BehaviorCollection.cs index 125384f9..3c95df71 100644 --- a/HandyControl/Interactivity/BehaviorCollection.cs +++ b/HandyControl/Interactivity/BehaviorCollection.cs @@ -22,14 +22,14 @@ namespace HandyControl.Interactivity internal override void ItemAdded(Behavior item) { - if (AssociatedObject == null) + if (item == null || AssociatedObject == null) return; item.Attach(AssociatedObject); } internal override void ItemRemoved(Behavior item) { - if (((IAttachedObject) item).AssociatedObject == null) + if (((IAttachedObject) item)?.AssociatedObject == null) return; item.Detach(); } diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj index 5a62c661..dee20316 100644 --- a/HandyControlDemo/HandyControlDemo.csproj +++ b/HandyControlDemo/HandyControlDemo.csproj @@ -381,6 +381,9 @@ CustomNonClientAreaWindow.xaml + + GrowlDemoWindow.xaml + NoNonClientAreaDragableWindow.xaml @@ -764,6 +767,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/HandyControlDemo/MainWindow.xaml b/HandyControlDemo/MainWindow.xaml index 99344426..85db7f43 100644 --- a/HandyControlDemo/MainWindow.xaml +++ b/HandyControlDemo/MainWindow.xaml @@ -33,7 +33,7 @@ - + \ No newline at end of file diff --git a/HandyControlDemo/MainWindow.xaml.cs b/HandyControlDemo/MainWindow.xaml.cs index 1287253a..bbd4e185 100644 --- a/HandyControlDemo/MainWindow.xaml.cs +++ b/HandyControlDemo/MainWindow.xaml.cs @@ -1,4 +1,7 @@ -namespace HandyControlDemo +using System; +using HandyControl.Controls; + +namespace HandyControlDemo { public partial class MainWindow { @@ -6,5 +9,19 @@ { InitializeComponent(); } + + protected override void OnActivated(EventArgs e) + { + base.OnActivated(e); + + Growl.SetGrowlParent(GrowlPanel, true); + } + + protected override void OnDeactivated(EventArgs e) + { + base.OnDeactivated(e); + + Growl.SetGrowlParent(GrowlPanel, false); + } } } \ No newline at end of file diff --git a/HandyControlDemo/Properties/Langs/Lang.Designer.cs b/HandyControlDemo/Properties/Langs/Lang.Designer.cs index 0ed9c7fa..8808342d 100644 --- a/HandyControlDemo/Properties/Langs/Lang.Designer.cs +++ b/HandyControlDemo/Properties/Langs/Lang.Designer.cs @@ -519,6 +519,15 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 消息通知示例 的本地化字符串。 + /// + public static string GrowlDemo { + get { + return ResourceManager.GetString("GrowlDemo", resourceCulture); + } + } + /// /// 查找类似 连接失败,请检查网络! 的本地化字符串。 /// @@ -672,6 +681,15 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 新建窗口 的本地化字符串。 + /// + public static string NewWindow { + get { + return ResourceManager.GetString("NewWindow", resourceCulture); + } + } + /// /// 查找类似 下一步 的本地化字符串。 /// diff --git a/HandyControlDemo/Properties/Langs/Lang.en.resx b/HandyControlDemo/Properties/Langs/Lang.en.resx index 5a368f22..da18fdc5 100644 --- a/HandyControlDemo/Properties/Langs/Lang.en.resx +++ b/HandyControlDemo/Properties/Langs/Lang.en.resx @@ -522,4 +522,10 @@ Please wait... + + Growl demo + + + New window + \ No newline at end of file diff --git a/HandyControlDemo/Properties/Langs/Lang.resx b/HandyControlDemo/Properties/Langs/Lang.resx index 05c82167..1718b806 100644 --- a/HandyControlDemo/Properties/Langs/Lang.resx +++ b/HandyControlDemo/Properties/Langs/Lang.resx @@ -522,4 +522,10 @@ 请稍后... + + 消息通知示例 + + + 新建窗口 + \ No newline at end of file diff --git a/HandyControlDemo/UserControl/Controls/GrowlDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/GrowlDemoCtl.xaml index 7f5b6932..7739acc0 100644 --- a/HandyControlDemo/UserControl/Controls/GrowlDemoCtl.xaml +++ b/HandyControlDemo/UserControl/Controls/GrowlDemoCtl.xaml @@ -6,14 +6,17 @@ DataContext="{Binding GrowlDemo,Source={StaticResource Locator}}" Background="{DynamicResource RegionBrush}"> - -