Skip to content
Open
1 change: 1 addition & 0 deletions Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
</Border>
<Line
x:Name="ProgressBar"
Style="{DynamicResource PendingLineStyle}"
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}"
Height="2"
Margin="12 0 12 0"
Expand Down
76 changes: 43 additions & 33 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public partial class MainWindow : IDisposable
// Window Animation
private const double DefaultRightMargin = 66; //* this value from base.xaml
private bool _isClockPanelAnimating = false;
private Storyboard _progressBarStoryboard;

// IDisposable
private bool _disposed = false;
Expand Down Expand Up @@ -1120,49 +1121,58 @@ private double VerticalTop(MonitorInfo screen)

private void InitProgressbarAnimation()
{
var progressBarStoryBoard = new Storyboard();
_progressBarStoryboard = new Storyboard();

var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100,
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0,
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
progressBarStoryBoard.Children.Add(da);
progressBarStoryBoard.Children.Add(da1);
progressBarStoryBoard.RepeatBehavior = RepeatBehavior.Forever;
var animationDuration = new Duration(TimeSpan.FromMilliseconds(1600));
var progressBarLength = ProgressBar.X2 - ProgressBar.X1;

da.Freeze();
da1.Freeze();

const string progressBarAnimationName = "ProgressBarAnimation";
var beginStoryboard = new BeginStoryboard
var lineEndAnimation = new DoubleAnimation
{
Name = progressBarAnimationName, Storyboard = progressBarStoryBoard
From = ProgressBar.X2,
To = ProgressBar.ActualWidth + progressBarLength,
Duration = animationDuration
};

var stopStoryboard = new StopStoryboard()
var lineStartAnimation = new DoubleAnimation
{
BeginStoryboardName = progressBarAnimationName
From = ProgressBar.X1,
To = ProgressBar.ActualWidth,
Duration = animationDuration
};

Storyboard.SetTarget(lineEndAnimation, ProgressBar);
Storyboard.SetTargetProperty(lineEndAnimation, new PropertyPath("(Line.X2)"));

Storyboard.SetTarget(lineStartAnimation, ProgressBar);
Storyboard.SetTargetProperty(lineStartAnimation, new PropertyPath("(Line.X1)"));

_progressBarStoryboard.Children.Add(lineEndAnimation);
_progressBarStoryboard.Children.Add(lineStartAnimation);
_progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;

lineEndAnimation.Freeze();
lineStartAnimation.Freeze();

ProgressBar.IsVisibleChanged -= ProgressBar_IsVisibleChanged;
ProgressBar.IsVisibleChanged += ProgressBar_IsVisibleChanged;

var trigger = new Trigger
{
Property = VisibilityProperty, Value = Visibility.Visible
};
trigger.EnterActions.Add(beginStoryboard);
trigger.ExitActions.Add(stopStoryboard);
_viewModel.ProgressBarVisibility = Visibility.Hidden;
}

var progressStyle = new Style(typeof(Line))
private void ProgressBar_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (_progressBarStoryboard == null)
{
BasedOn = FindResource("PendingLineStyle") as Style
};
progressStyle.RegisterName(progressBarAnimationName, beginStoryboard);
progressStyle.Triggers.Add(trigger);

ProgressBar.Style = progressStyle;
return;
}

_viewModel.ProgressBarVisibility = Visibility.Hidden;
if (ProgressBar.IsVisible)
{
_progressBarStoryboard.Begin(ProgressBar, true);
}
else
{
_progressBarStoryboard.Stop(ProgressBar);
}
}

private void WindowAnimation()
Expand Down
Loading