Skip to content

Commit faf2ba4

Browse files
committed
enhance: add TransitionMode prop for GrowlWindow.
1 parent 83fc434 commit faf2ba4

File tree

8 files changed

+164
-55
lines changed

8 files changed

+164
-55
lines changed

src/Net_40/HandyControl_Net_40/Themes/Theme.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12694,6 +12694,14 @@
1269412694
</ControlTemplate>
1269512695
</Setter.Value>
1269612696
</Setter>
12697+
<Style.Triggers>
12698+
<Trigger Property="hc:Growl.TransitionMode" Value="Bottom2Top">
12699+
<Setter Property="Margin" Value="10,0,10,10" />
12700+
</Trigger>
12701+
<Trigger Property="hc:Growl.TransitionMode" Value="Bottom2TopWithFade">
12702+
<Setter Property="Margin" Value="10,0,10,10" />
12703+
</Trigger>
12704+
</Style.Triggers>
1269712705
</Style>
1269812706
<Style BasedOn="{StaticResource ImageSelectorBaseStyle}" TargetType="hc:ImageSelector" />
1269912707
<Style TargetType="hc:ImageViewer">

src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private static void InitGrowlPanel(Panel panel)
291291
{
292292
foreach (var item in panel.Children.OfType<Growl>())
293293
{
294-
item.Close(false);
294+
item.Close(invokeParam: false, isClear: true);
295295
}
296296
};
297297
panel.ContextMenu = new ContextMenu
@@ -354,9 +354,9 @@ private static void ShowGlobal(GrowlInfo growlInfo)
354354
GrowlWindow = new GrowlWindow();
355355
GrowlWindow.Show();
356356
InitGrowlPanel(GrowlWindow.GrowlPanel);
357-
GrowlWindow.Init();
358357
}
359358

359+
GrowlWindow.UpdatePosition(Growl.GetTransitionMode(Application.Current.MainWindow));
360360
GrowlWindow.Show(true);
361361

362362
var ctl = new Growl
@@ -408,7 +408,7 @@ private static void Show(GrowlInfo growlInfo)
408408
ConfirmStr = growlInfo.ConfirmStr,
409409
CancelStr = growlInfo.CancelStr,
410410
Type = growlInfo.Type,
411-
_waitTime = Math.Max(growlInfo.WaitTime, MinWaitTime)
411+
_waitTime = Math.Max(growlInfo.WaitTime, MinWaitTime),
412412
};
413413

414414
if (!string.IsNullOrEmpty(growlInfo.Token))
@@ -424,9 +424,11 @@ private static void Show(GrowlInfo growlInfo)
424424
GrowlPanel ??= CreateDefaultPanel();
425425
ShowInternal(GrowlPanel, ctl);
426426

427-
var transitionMode = GetTransitionMode(ctl);
427+
var transitionMode = GetTransitionMode(GrowlPanel);
428428
GrowlPanel.VerticalAlignment = GetPanelVerticalAlignment(transitionMode);
429429
GrowlPanel.HorizontalAlignment = GetPanelHorizontalAlignment(transitionMode);
430+
GrowlPanel.SetValue(InverseStackPanel.IsInverseEnabledProperty,
431+
transitionMode is TransitionMode.Bottom2Top or TransitionMode.Bottom2TopWithFade);
430432
}
431433
}
432434
#if NET40
@@ -446,7 +448,7 @@ private static Panel CreateDefaultPanel()
446448
return null;
447449
}
448450

449-
var panel = new SimpleStackPanel();
451+
var panel = new InverseStackPanel();
450452

451453
InitGrowlPanel(panel);
452454
SetIsCreatedAutomatically(panel, true);
@@ -830,14 +832,15 @@ public static void AskGlobal(GrowlInfo growlInfo)
830832
/// <summary>
831833
/// 关闭
832834
/// </summary>
833-
private void Close(bool invokeParam)
835+
private void Close(bool invokeParam, bool isClear = false)
834836
{
835-
if (ActionBeforeClose?.Invoke(invokeParam) == false)
837+
if (!isClear && ActionBeforeClose?.Invoke(invokeParam) == false)
836838
{
837839
return;
838840
}
839841

840842
_timerClose?.Stop();
843+
Panel.SetZIndex(this, int.MinValue);
841844
StartTransition(true, OnStoryboardCompleted);
842845
return;
843846

@@ -942,16 +945,19 @@ private Storyboard CreateStoryboard(bool isClose, TransitionMode transitionMode)
942945
{
943946
var transformLength = GetTransformLength(isClose, transitionMode);
944947
var transformAnimation = CreateTransformAnimation(isClose, transitionMode, transformLength);
945-
_gridMain.RenderTransform = CreateRenderTransform(isClose, transitionMode, transformLength);
946-
947948
var storyboard = new Storyboard
948949
{
949950
Duration = transformAnimation.Duration
950951
};
951-
Storyboard.SetTarget(transformAnimation, _gridMain);
952-
storyboard.Children.Add(transformAnimation);
953952

954-
if (CreateFadeAnimation(transitionMode) is not { } fadeAnimation)
953+
if (transitionMode is not TransitionMode.Fade)
954+
{
955+
_gridMain.RenderTransform = CreateRenderTransform(isClose, transitionMode, transformLength);
956+
Storyboard.SetTarget(transformAnimation, _gridMain);
957+
storyboard.Children.Add(transformAnimation);
958+
}
959+
960+
if (CreateFadeAnimation(isClose, transitionMode) is not { } fadeAnimation)
955961
{
956962
return storyboard;
957963
}
@@ -970,7 +976,7 @@ private double GetTransformLength(bool isClose, TransitionMode transitionMode)
970976
TransitionMode.Left2Right or TransitionMode.Left2RightWithFade => -ActualWidth,
971977
TransitionMode.Bottom2Top or TransitionMode.Bottom2TopWithFade => ActualHeight,
972978
TransitionMode.Top2Bottom or TransitionMode.Top2BottomWithFade => -ActualHeight,
973-
_ => 0
979+
_ => ActualWidth
974980
};
975981

976982

@@ -1007,6 +1013,9 @@ private static Transform CreateRenderTransform(bool isClose, TransitionMode tran
10071013
case Orientation.Vertical:
10081014
((TranslateTransform) transformGroup.Children[TranslateTransformIndex]).Y = transformLength;
10091015
break;
1016+
default:
1017+
((TranslateTransform) transformGroup.Children[TranslateTransformIndex]).X = transformLength;
1018+
break;
10101019
}
10111020

10121021
return transformGroup;
@@ -1029,23 +1038,29 @@ private static DoubleAnimation CreateTransformAnimation(bool isClose, Transition
10291038
new PropertyPath(
10301039
$"(UIElement.RenderTransform).(TransformGroup.Children)[{TranslateTransformIndex}].(TranslateTransform.Y)"));
10311040
break;
1041+
default:
1042+
Storyboard.SetTargetProperty(animation,
1043+
new PropertyPath(
1044+
$"(UIElement.RenderTransform).(TransformGroup.Children)[{TranslateTransformIndex}].(TranslateTransform.X)"));
1045+
break;
10321046
}
10331047

10341048
return animation;
10351049
}
10361050

1037-
private static DoubleAnimation CreateFadeAnimation(TransitionMode transitionMode)
1051+
private static DoubleAnimation CreateFadeAnimation(bool isClose, TransitionMode transitionMode)
10381052
{
10391053
if (transitionMode is TransitionMode.Right2Left or
10401054
TransitionMode.Left2Right or
10411055
TransitionMode.Bottom2Top or
1042-
TransitionMode.Top2Bottom)
1056+
TransitionMode.Top2Bottom or
1057+
TransitionMode.Custom)
10431058
{
10441059
return null;
1045-
}
1060+
}
10461061

1047-
var animation = AnimationHelper.CreateAnimation(1);
1048-
animation.From = 0;
1062+
var animation = AnimationHelper.CreateAnimation(isClose ? 0 : 1);
1063+
animation.From = isClose ? 1 : 0;
10491064
Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Opacity)"));
10501065

10511066
return animation;
@@ -1059,31 +1074,24 @@ TransitionMode.Right2Left or TransitionMode.Right2LeftWithFade or TransitionMode
10591074
or TransitionMode.Left2RightWithFade => Orientation.Horizontal,
10601075
TransitionMode.Bottom2Top or TransitionMode.Bottom2TopWithFade or TransitionMode.Top2Bottom
10611076
or TransitionMode.Top2BottomWithFade => Orientation.Vertical,
1062-
_ => null
1077+
_ => Orientation.Horizontal
10631078
};
10641079
}
10651080

1066-
private static VerticalAlignment GetPanelVerticalAlignment(TransitionMode transitionMode)
1081+
internal static VerticalAlignment GetPanelVerticalAlignment(TransitionMode transitionMode)
10671082
{
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-
};
1083+
return VerticalAlignment.Stretch;
10761084
}
10771085

1078-
private static HorizontalAlignment GetPanelHorizontalAlignment(TransitionMode transitionMode)
1086+
internal static HorizontalAlignment GetPanelHorizontalAlignment(TransitionMode transitionMode)
10791087
{
10801088
return transitionMode switch
10811089
{
10821090
TransitionMode.Right2Left or TransitionMode.Right2LeftWithFade => HorizontalAlignment.Right,
10831091
TransitionMode.Left2Right or TransitionMode.Left2RightWithFade => HorizontalAlignment.Left,
10841092
TransitionMode.Bottom2Top or TransitionMode.Bottom2TopWithFade or TransitionMode.Top2Bottom
10851093
or TransitionMode.Top2BottomWithFade => HorizontalAlignment.Center,
1086-
_ => HorizontalAlignment.Stretch
1094+
_ => HorizontalAlignment.Right
10871095
};
10881096
}
10891097
}

src/Shared/HandyControl_Shared/Controls/Growl/GrowlWindow.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Windows;
33
using System.Windows.Controls;
4+
using HandyControl.Data;
45
using HandyControl.Tools;
56
using HandyControl.Tools.Interop;
67

@@ -15,11 +16,8 @@ internal GrowlWindow()
1516
WindowStyle = WindowStyle.None;
1617
AllowsTransparency = true;
1718

18-
GrowlPanel = new StackPanel
19-
{
20-
VerticalAlignment = VerticalAlignment.Top
21-
};
22-
19+
Growl.SetTransitionStoryboard(this, Growl.GetTransitionStoryboard(Application.Current.MainWindow));
20+
GrowlPanel = new InverseStackPanel();
2321
Content = new ScrollViewer
2422
{
2523
VerticalScrollBarVisibility = ScrollBarVisibility.Hidden,
@@ -28,12 +26,24 @@ internal GrowlWindow()
2826
};
2927
}
3028

31-
internal void Init()
29+
internal void UpdatePosition(TransitionMode transitionMode)
3230
{
3331
var desktopWorkingArea = SystemParameters.WorkArea;
3432
Height = desktopWorkingArea.Height;
35-
Left = desktopWorkingArea.Right - Width;
3633
Top = 0;
34+
35+
var panelHorizontalAlignment = Growl.GetPanelHorizontalAlignment(transitionMode);
36+
Left = panelHorizontalAlignment switch
37+
{
38+
HorizontalAlignment.Right => desktopWorkingArea.Right - Width,
39+
HorizontalAlignment.Left => desktopWorkingArea.Left,
40+
HorizontalAlignment.Center => desktopWorkingArea.Left + (desktopWorkingArea.Width - Width) * 0.5,
41+
_ => desktopWorkingArea.Right - Width
42+
};
43+
44+
Growl.SetTransitionMode(this, transitionMode);
45+
GrowlPanel.SetValue(InverseStackPanel.IsInverseEnabledProperty,
46+
transitionMode is TransitionMode.Bottom2Top or TransitionMode.Bottom2TopWithFade);
3747
}
3848

3949
protected override void OnSourceInitialized(EventArgs e)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Windows;
3+
using HandyControl.Data;
4+
5+
namespace HandyControl.Controls;
6+
7+
public class InverseStackPanel : SimpleStackPanel
8+
{
9+
public static readonly DependencyProperty IsInverseEnabledProperty = DependencyProperty.Register(
10+
nameof(IsInversed), typeof(bool), typeof(InverseStackPanel),
11+
new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.AffectsMeasure));
12+
13+
public bool IsInversed
14+
{
15+
get => (bool) GetValue(IsInverseEnabledProperty);
16+
set => SetValue(IsInverseEnabledProperty, ValueBoxes.BooleanBox(value));
17+
}
18+
19+
protected override Size ArrangeOverride(Size arrangeSize)
20+
{
21+
if (!IsInversed)
22+
{
23+
return base.ArrangeOverride(arrangeSize);
24+
}
25+
26+
var rcChild = new Rect(arrangeSize);
27+
double previousChildSize;
28+
29+
if (Orientation == System.Windows.Controls.Orientation.Horizontal)
30+
{
31+
rcChild.X = arrangeSize.Width;
32+
33+
foreach (var child in GetVisibleChildren())
34+
{
35+
previousChildSize = child.DesiredSize.Width;
36+
rcChild.X -= previousChildSize;
37+
rcChild.Width = previousChildSize;
38+
rcChild.Height = Math.Max(arrangeSize.Height, child.DesiredSize.Height);
39+
40+
child.Arrange(rcChild);
41+
}
42+
}
43+
else
44+
{
45+
rcChild.Y = arrangeSize.Height;
46+
47+
foreach (var child in GetVisibleChildren())
48+
{
49+
previousChildSize = child.DesiredSize.Height;
50+
rcChild.Y -= previousChildSize;
51+
rcChild.Height = previousChildSize;
52+
rcChild.Width = Math.Max(arrangeSize.Width, child.DesiredSize.Width);
53+
54+
child.Arrange(rcChild);
55+
}
56+
}
57+
58+
return arrangeSize;
59+
}
60+
}

0 commit comments

Comments
 (0)