@@ -47,11 +47,13 @@ public class Growl : Control
4747 "ShowMode" , typeof ( GrowlShowMode ) , typeof ( Growl ) ,
4848 new FrameworkPropertyMetadata ( default ( GrowlShowMode ) , FrameworkPropertyMetadataOptions . Inherits ) ) ;
4949
50- public static readonly DependencyProperty TransitionModeProperty = DependencyProperty . Register (
51- nameof ( TransitionMode ) , typeof ( TransitionMode ) , typeof ( Growl ) , new PropertyMetadata ( default ( TransitionMode ) ) ) ;
50+ public static readonly DependencyProperty TransitionModeProperty = DependencyProperty . RegisterAttached (
51+ "TransitionMode" , typeof ( TransitionMode ) , typeof ( Growl ) ,
52+ new FrameworkPropertyMetadata ( default ( TransitionMode ) , FrameworkPropertyMetadataOptions . Inherits ) ) ;
5253
53- public static readonly DependencyProperty TransitionStoryboardProperty = DependencyProperty . Register (
54- nameof ( TransitionStoryboard ) , typeof ( Storyboard ) , typeof ( Growl ) , new PropertyMetadata ( default ( Storyboard ) ) ) ;
54+ public static readonly DependencyProperty TransitionStoryboardProperty = DependencyProperty . RegisterAttached (
55+ "TransitionStoryboard" , typeof ( Storyboard ) , typeof ( Growl ) ,
56+ new FrameworkPropertyMetadata ( null , FrameworkPropertyMetadataOptions . Inherits ) ) ;
5557
5658 public static readonly DependencyProperty ShowDateTimeProperty = DependencyProperty . Register (
5759 nameof ( ShowDateTime ) , typeof ( bool ) , typeof ( Growl ) , new PropertyMetadata ( ValueBoxes . TrueBox ) ) ;
@@ -105,18 +107,6 @@ public class Growl : Control
105107 /// </summary>
106108 public static Panel GrowlPanel { get ; set ; }
107109
108- public TransitionMode TransitionMode
109- {
110- get => ( TransitionMode ) GetValue ( TransitionModeProperty ) ;
111- set => SetValue ( TransitionModeProperty , value ) ;
112- }
113-
114- public Storyboard TransitionStoryboard
115- {
116- get => ( Storyboard ) GetValue ( TransitionStoryboardProperty ) ;
117- set => SetValue ( TransitionStoryboardProperty , value ) ;
118- }
119-
120110 public InfoType Type
121111 {
122112 get => ( InfoType ) GetValue ( TypeProperty ) ;
@@ -231,6 +221,18 @@ public static void SetShowMode(DependencyObject element, GrowlShowMode value) =>
231221 public static GrowlShowMode GetShowMode ( DependencyObject element ) =>
232222 ( GrowlShowMode ) element . GetValue ( ShowModeProperty ) ;
233223
224+ public static void SetTransitionMode ( DependencyObject element , TransitionMode value )
225+ => element . SetValue ( TransitionModeProperty , value ) ;
226+
227+ public static TransitionMode GetTransitionMode ( DependencyObject element )
228+ => ( TransitionMode ) element . GetValue ( TransitionModeProperty ) ;
229+
230+ public static void SetTransitionStoryboard ( DependencyObject element , Storyboard value )
231+ => element . SetValue ( TransitionStoryboardProperty , value ) ;
232+
233+ public static Storyboard GetTransitionStoryboard ( DependencyObject element )
234+ => ( Storyboard ) element . GetValue ( TransitionStoryboardProperty ) ;
235+
234236 public static void SetGrowlParent ( DependencyObject element , bool value ) =>
235237 element . SetValue ( GrowlParentProperty , ValueBoxes . BooleanBox ( value ) ) ;
236238
@@ -371,7 +373,6 @@ private static void ShowGlobal(GrowlInfo growlInfo)
371373 CancelStr = growlInfo . CancelStr ,
372374 Type = growlInfo . Type ,
373375 _waitTime = Math . Max ( growlInfo . WaitTime , MinWaitTime ) ,
374- FlowDirection = growlInfo . FlowDirection
375376 } ;
376377
377378 ShowInternal ( GrowlWindow . GrowlPanel , ctl ) ;
@@ -422,6 +423,10 @@ private static void Show(GrowlInfo growlInfo)
422423 // GrowlPanel is null, we create it automatically
423424 GrowlPanel ??= CreateDefaultPanel ( ) ;
424425 ShowInternal ( GrowlPanel , ctl ) ;
426+
427+ var transitionMode = GetTransitionMode ( ctl ) ;
428+ GrowlPanel . VerticalAlignment = GetPanelVerticalAlignment ( transitionMode ) ;
429+ GrowlPanel . HorizontalAlignment = GetPanelHorizontalAlignment ( transitionMode ) ;
425430 }
426431 }
427432#if NET40
@@ -435,40 +440,33 @@ private static Panel CreateDefaultPanel()
435440 FrameworkElement element = WindowHelper . GetActiveWindow ( ) ;
436441 var decorator = VisualHelper . GetChild < AdornerDecorator > ( element ) ;
437442
438- if ( decorator != null )
443+ var layer = decorator ? . AdornerLayer ;
444+ if ( layer == null )
439445 {
440- var layer = decorator . AdornerLayer ;
441- if ( layer != null )
442- {
443- var panel = new StackPanel
444- {
445- VerticalAlignment = VerticalAlignment . Top
446- } ;
446+ return null ;
447+ }
447448
448- InitGrowlPanel ( panel ) ;
449- SetIsCreatedAutomatically ( panel , true ) ;
449+ var panel = new SimpleStackPanel ( ) ;
450450
451- var scrollViewer = new ScrollViewer
452- {
453- HorizontalAlignment = HorizontalAlignment . Right ,
454- VerticalScrollBarVisibility = ScrollBarVisibility . Hidden ,
455- IsInertiaEnabled = true ,
456- IsPenetrating = true ,
457- Content = panel
458- } ;
459-
460- var container = new AdornerContainer ( layer )
461- {
462- Child = scrollViewer
463- } ;
451+ InitGrowlPanel ( panel ) ;
452+ SetIsCreatedAutomatically ( panel , true ) ;
464453
465- layer . Add ( container ) ;
454+ var scrollViewer = new ScrollViewer
455+ {
456+ VerticalScrollBarVisibility = ScrollBarVisibility . Hidden ,
457+ IsInertiaEnabled = true ,
458+ IsPenetrating = true ,
459+ Content = panel
460+ } ;
466461
467- return panel ;
468- }
469- }
462+ var container = new AdornerContainer ( layer )
463+ {
464+ Child = scrollViewer
465+ } ;
470466
471- return null ;
467+ layer . Add ( container ) ;
468+
469+ return panel ;
472470 }
473471
474472 private static void RemoveDefaultPanel ( Panel panel )
@@ -918,7 +916,7 @@ public static void ClearGlobal()
918916
919917 private void StartTransition ( bool isClose , Action completed = null )
920918 {
921- var actualStoryboard = TransitionStoryboard ?? CreateStoryboard ( isClose , TransitionMode ) ;
919+ var actualStoryboard = GetTransitionStoryboard ( this ) ?? CreateStoryboard ( isClose , GetTransitionMode ( this ) ) ;
922920 if ( actualStoryboard is null )
923921 {
924922 return ;
@@ -1064,4 +1062,28 @@ TransitionMode.Bottom2Top or TransitionMode.Bottom2TopWithFade or TransitionMode
10641062 _ => null
10651063 } ;
10661064 }
1065+
1066+ private static VerticalAlignment GetPanelVerticalAlignment ( TransitionMode transitionMode )
1067+ {
1068+ return transitionMode switch
1069+ {
1070+ TransitionMode . Right2Left or TransitionMode . Right2LeftWithFade or TransitionMode . Left2Right
1071+ or TransitionMode . Left2RightWithFade => VerticalAlignment . Top ,
1072+ TransitionMode . Bottom2Top or TransitionMode . Bottom2TopWithFade => VerticalAlignment . Bottom ,
1073+ TransitionMode . Top2Bottom or TransitionMode . Top2BottomWithFade => VerticalAlignment . Top ,
1074+ _ => VerticalAlignment . Stretch
1075+ } ;
1076+ }
1077+
1078+ private static HorizontalAlignment GetPanelHorizontalAlignment ( TransitionMode transitionMode )
1079+ {
1080+ return transitionMode switch
1081+ {
1082+ TransitionMode . Right2Left or TransitionMode . Right2LeftWithFade => HorizontalAlignment . Right ,
1083+ TransitionMode . Left2Right or TransitionMode . Left2RightWithFade => HorizontalAlignment . Left ,
1084+ TransitionMode . Bottom2Top or TransitionMode . Bottom2TopWithFade or TransitionMode . Top2Bottom
1085+ or TransitionMode . Top2BottomWithFade => HorizontalAlignment . Center ,
1086+ _ => HorizontalAlignment . Stretch
1087+ } ;
1088+ }
10671089}
0 commit comments