Skip to content

Commit

Permalink
Added an animation when navigating ColorPicker (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Feb 16, 2022
1 parent 7dbd5b1 commit 9c1ff80
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ColorPicker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private void InitUI()
PageContent.Content = Global.PickerPage; // Set startup page

Closed += (o, e) => HistoryManager.Save();
PageContent.Navigated += (o, e) => AnimatePage();
}

private void MinimizeBtn_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -126,6 +127,7 @@ private void ConverterTabBtn_Click(object sender, RoutedEventArgs e)
CheckButton(ConverterTabBtn); // Check the "Converter" button

PageContent.Navigate(Global.ConverterPage); // Navigate

}

private void SettingsTabBtn_Click(object sender, RoutedEventArgs e)
Expand All @@ -150,5 +152,21 @@ private void PinBtn_Click(object sender, RoutedEventArgs e)
PinBtn.Content = Topmost ? "\uF604" : "\uF602"; // Set text
PinToolTip.Content = Topmost ? Properties.Resources.Unpin : Properties.Resources.Pin; // Set text
}

private void AnimatePage()
{
Storyboard storyboard = new();

ThicknessAnimationUsingKeyFrames t = new();
t.KeyFrames.Add(new SplineThicknessKeyFrame(new(0, 30, 0, 0), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
t.KeyFrames.Add(new SplineThicknessKeyFrame(new(0), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.1))));
t.AccelerationRatio = 0.5;

storyboard.Children.Add(t);

Storyboard.SetTargetName(t, PageContent.Name);
Storyboard.SetTargetProperty(t, new(Frame.MarginProperty));
storyboard.Begin(this);
}
}
}

0 comments on commit 9c1ff80

Please sign in to comment.