Windows Phone应用程序上的ShakeGesture库中出现异常 [英] Strange in ShakeGesture Library on Windows Phone Application

查看:94
本文介绍了Windows Phone应用程序上的ShakeGesture库中出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了Windows Phone shakegesture库的问题. 我构建了一个应用程序,该应用程序会发出震撼的声音,并且可以正常工作,但是奇怪的错误使我感到困惑.我有两页.这是我分开的代码:

i've a problem with windows phone shakegesture library. I build an application which its shaking the sound will go out and its work nicely but strange bug make me confused. I've two page of it. This is my seperated code :

void Instance_ShakeGesture1(object sender, ShakeGestureEventArgs e)
    {            
        Stream stream = TitleContainer.OpenStream("Sounds/C.wav");
        effect = SoundEffect.FromStream(stream);
        effectInstance = effect.CreateInstance();
        if (effectInstance.State != SoundState.Playing || effectInstance == null)
        {
            FrameworkDispatcher.Update();
            effectInstance.Play();
        }

        else if (effectInstance.State == SoundState.Playing || effectInstance != null)
        {
            effectInstance.Stop();
        }
    }

    void Instance_ShakeGesture2(object sender, ShakeGestureEventArgs e)
    {
        Stream stream = TitleContainer.OpenStream("Sounds/D.wav");
        effect = SoundEffect.FromStream(stream);
        effectInstance = effect.CreateInstance();
        FrameworkDispatcher.Update();
        if (effectInstance.State == SoundState.Stopped || effectInstance == null)
        {
            effectInstance.Play();
        }

        else if (effectInstance.State == SoundState.Playing || effectInstance != null)
        {
            effectInstance.Stop();
        }
    }

Instance_ShakeGesture1是我在第1页和第2页中的Instance_ShakeGesture2摇动时播放音乐的过程. 摇动时出现奇怪的错误,如果我摇动第1页,则Instance_ShakeGesture1将在执行后尝试移动到第2页,摇动它将首先执行Instance_ShakeGesture1,然后执行Instance_ShakeGesture2. 当我尝试先摇晃第2页而不是第1页时,问题就来了.Instance_ShakeGesture2将首先执行,而Instance_ShakeGesture2在第二次执行. 当我使用断点时,我知道此错误. 有人知道如何解决这个问题吗?之前感谢:)

Instance_ShakeGesture1 is my procedure to play a music when its shaking in Page 1 and Instance_ShakeGesture2 in Page 2. Strange bug was come when its shaking, if i shake page 1 Instance_ShakeGesture1 will executed after that I try move to page 2 and i shake it will execute Instance_ShakeGesture1 first and than Instance_ShakeGesture2. The Problem was come same when i try to shake Page 2 first and than Page 1, Instance_ShakeGesture2 will execute first and Instance_ShakeGesture2 in the second. I know this bug when i use breakpoint. Anyone know how to solve this problem? Thanks before :)

推荐答案

尝试一下,它对我有用,

try this, it worked for me,

protected override void OnBackKeyPress(CancelEventArgs e)
{
    e.Cancel = false;
    ShakeGesturesHelper.Instance.ShakeGesture -= new EventHandler<ShakeGestureEventArgs>(Instance_ShakeGesture1);
}

因为您应该在离开首页时删除事件.这样,您可以在按下返回键按钮时清理hakeGestureEventArgs.

Because you should delete the events when you leaving first page. So you can clean hakeGestureEventArgs when back key button is pressed.

这篇关于Windows Phone应用程序上的ShakeGesture库中出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆