未经授权的访问异常未得到处理

时间:2012-09-12 11:38:23

标签: windows-phone-7 xaml windows-mobile navigationservice

我需要从click事件中调用xaml文件,我使用c#进行开发。我已经创建了Xaml文件并完成了设计部分,现在我需要从我的应用程序中调用这个xaml文件。我尝试了以下

NavigationService.Navigate(new Uri("/xxx.xaml", UriKind.Relative));

但是它给了我以下错误,

unauthorized access exception was unhandled. 
Invalid cross-thread access.

这有什么问题?我在我的一个函数之间调用这个xaml文件,我需要在这个函数中显示用.xaml指定的屏幕。

1 个答案:

答案 0 :(得分:3)

好像你试图从后台线程调用Navigate方法。从UI线程调用它,如下所示:

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

从评论中编辑:

Dispatcher.BeginInvoke(() =>
{
   if(MessageBox.Show("message", "title", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
   {
       NavigationService.Navigate(new Uri("/xxx.xaml", UriKind.Relative));
   }
});
相关问题