在隐藏WP8应用栏后执行某些操作

时间:2014-06-04 11:17:48

标签: silverlight animation windows-phone-8 popupmenu application-bar

我正在为app bar图标按钮实现我自己的弹出菜单(类似于PhoneFlipMenu工具)。我使用垂直StackPanel作为弹出窗口,当点击相应的应用栏按钮时,我需要用动画显示它。代码如下所示:

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();
}

主要问题是动画在隐藏应用程序栏之前开始。结果,弹出菜单稍后跳了一下。如何在应用程序栏完全隐藏后运行动画?

2 个答案:

答案 0 :(得分:0)

动画完成后尝试隐藏应用栏。

 storyboard.Completed += storyboard_Completed;


    void storyboard_Completed(object sender, EventArgs e)
    {
        ApplicationBar.IsVisible = false;
    }

答案 1 :(得分:0)

您可以使用Dispatcher或DispatcherTimer等待隐藏appbar。以下是使用Dispatcher的例子:

private void ApplicationBarIconButton_OnClick(object sender, EventArgs e)
{
    ApplicationBar.IsVisible = false;
    WaitForAppBarThenShowMenu();
}

private void WaitForAppBarThenShowMenu()
{
    if (ApplicationBar.IsVisible)
    {
        Dispatcher.BeginInvoke(WaitForAppBarThenShowMenu);
    }
    else
    {
        AnimatePopupMenuListCommands();
    }
}

老答案 - 不工作 我相信你可以订阅ApplicationBar的StateChanged event,然后开始你的故事。

EventHandler<ApplicationBarStateChangedEventArgs> stateChanged = null;
stateChanged = (s,e) => 
{
    ApplicationBar.StateChanged -= stateChanged;
    AnimatePopupMenuListCommands(true);
};
ApplicationBar.StateChanged += stateChanged;
ApplicationBar.IsVisible = false;