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}"> - -