简体   繁体   English

WP8应用栏被隐藏后要做的事情

[英]Doing something after WP8 app bar has been hidden

I'm in the process of implementing my own popup menu for app bar icon buttons (something similar to the PhoneFlipMenu tool). 我正在为应用程序栏图标按钮实现自己的弹出菜单(类似于PhoneFlipMenu工具)。 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. 我正在使用垂直的StackPanel作为弹出窗口,并且在单击相应的应用栏按钮时需要将其与动画一起显示。 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. 您可以等待使用Dispatcher或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. 旧答案-不起作用,我相信您可以订阅ApplicationBar的StateChanged事件 ,然后开始故事。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM