本文介绍了从Accelerometer.ReadingChanged调用NavigationService.Navigate会引发NotSupportedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面,您可以看到发生抖动事件时用于调用页面的代码.但是,页面会弹出,但同时应用程序冻结,而我无法进行任何其他用户输入,例如单击按钮.

In the following you can see the code I use to call a page if a shake event happens. However, the page pops up but in the same moment the app freezes and I can't do any further user input, for example clicking a button.

void accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
{
    //double X, Y, Z;
    if (e.X > 1.5)
    {
        Dispatcher.BeginInvoke( () => { 
            NavigationService.Navigate(new Uri("/Bars/DetailBar.xaml", UriKind.Relative));
        } ); 
    } 
}

调试器告诉我,"NavigationFailed"和一个"System.NotSupportedException".怎么了?

the debugger tells me, that the "NavigationFailed" and that there is an "System.NotSupportedException". What's going wrong?

推荐答案

读数可能发生得太快,并且导致了多个导航的发生.尝试退订该事件:

The readings are likely happening too quickly and you are causing multiple Navigations to occur. Try unsubscribing from the event:

void accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
{
    //double X, Y, Z;
    if (e.X > 1.5)
    {
        accelerometer.ReadingChanged -= accelerometer_ReadingChanged;

        Dispatcher.BeginInvoke( () => {    
            NavigationService.Navigate(new Uri("/Bars/DetailBar.xaml", UriKind.Relative));
        }); 

    } 
}

这篇关于从Accelerometer.ReadingChanged调用NavigationService.Navigate会引发NotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 05:41