I'm in the process of implementing my own popup menu for app bar icon buttons (something similar to the PhoneFlipMenu tool). I'm using a vertical StackPanel for my popup, and I need to display it with animation when the corresponding app bar button is clicked. The code looks like this:
private void appBarIconButtonList_Click(object sender, EventArgs e)
{
ApplicationBar.IsVisible = false;
AnimatePopupMenuListCommands(true);
}
private void AnimatePopupMenuListCommands(bool openMenu)
{
PlaneProjection planeProjection = popupMenuListCommands.Projection as PlaneProjection;
DoubleAnimation anima = new DoubleAnimation();
if (openMenu)
{
anima.From = 90;
anima.To = 0;
}
else
{
anima.From = 0;
anima.To = 90;
}
anima.Duration = new Duration(TimeSpan.FromSeconds(0.1));
Storyboard.SetTarget(anima, planeProjection);
Storyboard.SetTargetProperty(anima, new PropertyPath(PlaneProjection.RotationXProperty));
Storyboard storyboard = new Storyboard();
storyboard.Children.Add(anima);
storyboard.Begin();
}
The main problem is that the animation begins before the application bar is hidden. As a result, the popup menu jumps a little bit after that. How to run the animation after the application bar has been totally hidden?
Try to hide application bar after the animation is complete.
storyboard.Completed += storyboard_Completed;
void storyboard_Completed(object sender, EventArgs e)
{
ApplicationBar.IsVisible = false;
}
You could wait for the appbar to be hidden using the Dispatcher or a DispatcherTimer. Here is an exmaple using the Dispatcher:
private void ApplicationBarIconButton_OnClick(object sender, EventArgs e)
{
ApplicationBar.IsVisible = false;
WaitForAppBarThenShowMenu();
}
private void WaitForAppBarThenShowMenu()
{
if (ApplicationBar.IsVisible)
{
Dispatcher.BeginInvoke(WaitForAppBarThenShowMenu);
}
else
{
AnimatePopupMenuListCommands();
}
}
OLD ANSWER - DOES NOT WORK I believe you can subscribe to the StateChanged event of the ApplicationBar and then start your story.
EventHandler<ApplicationBarStateChangedEventArgs> stateChanged = null;
stateChanged = (s,e) =>
{
ApplicationBar.StateChanged -= stateChanged;
AnimatePopupMenuListCommands(true);
};
ApplicationBar.StateChanged += stateChanged;
ApplicationBar.IsVisible = false;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.