Fix wrong appearance in menu size and position when switching from loading menu to final sub menu

This commit is contained in:
Peter Kirmeier 2023-08-20 14:03:58 +02:00
parent cfd53b516e
commit 4ac3d1eb3a
3 changed files with 31 additions and 3 deletions

View file

@ -355,8 +355,14 @@ namespace SystemTrayMenu.Business
if (menuData.DirectoryState != MenuDataDirectoryState.Undefined)
{
// Sub Menu (completed)
// As we need to render it during calculations but we don't want to show flickering windows,
// we just hide it for just a moment and show it again after updates have been applied.
// In order to hide it via Opacity we have to cancel any Fade animations.
menu.StopFade();
menu.Opacity = 0D;
menu.AddItemsToMenu(menuData.RowDatas, menuData.DirectoryState);
AdjustMenusSizeAndLocation(menu.Level);
menu.Opacity = 1D;
}
else
{

View file

@ -18,7 +18,7 @@
<Window.Triggers>
<EventTrigger RoutedEvent="local:Menu.FadeToTransparent">
<BeginStoryboard>
<BeginStoryboard Name="FadeToTransparentStoryboard">
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Opacity"
@ -27,7 +27,7 @@
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="local:Menu.FadeIn">
<BeginStoryboard>
<BeginStoryboard Name="FadeInStoryboard">
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Opacity"
@ -36,7 +36,7 @@
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="local:Menu.FadeOut">
<BeginStoryboard>
<BeginStoryboard Name="FadeOutStoryboard">
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Opacity"
@ -45,6 +45,11 @@
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="local:Menu.FadeStop">
<StopStoryboard BeginStoryboardName="FadeToTransparentStoryboard" />
<StopStoryboard BeginStoryboardName="FadeInStoryboard" />
<StopStoryboard BeginStoryboardName="FadeOutStoryboard"/>
</EventTrigger>
</Window.Triggers>
<Window.Resources>

View file

@ -37,6 +37,9 @@ namespace SystemTrayMenu.UserInterface
private static readonly RoutedEvent FadeOutEvent = EventManager.RegisterRoutedEvent(
nameof(FadeOut), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Menu));
private static readonly RoutedEvent FadeStopEvent = EventManager.RegisterRoutedEvent(
nameof(FadeStop), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Menu));
private readonly string folderPath;
private bool isShellContextMenuOpen;
@ -243,6 +246,12 @@ namespace SystemTrayMenu.UserInterface
remove { RemoveHandler(FadeOutEvent, value); }
}
internal event RoutedEventHandler FadeStop
{
add { AddHandler(FadeStopEvent, value); }
remove { RemoveHandler(FadeStopEvent, value); }
}
internal enum StartLocation
{
Point,
@ -503,6 +512,14 @@ namespace SystemTrayMenu.UserInterface
}
}
internal void StopFade()
{
if (Settings.Default.UseFading)
{
RaiseEvent(new(routedEvent: FadeStopEvent));
}
}
/// <summary>
/// Update the position and size of the menu.
/// </summary>