积极答复者
页面转换问题

问题
答案
-
-
调试时,一直运行System.Diagnostics.Debugger.Break();的原因是异常发生时跳转的默认页面不成功,即在此例中找不到Demo文件夹下的MainPage.xaml。
RootFrame.Navigate(new System.Uri("/Demo;component/MainPage.xaml", System.UriKind.Relative));这段代码需要中修改"/Demo;component/MainPage.xaml",将Demo改为你的工程中的存放MainPage.xaml的文件夹名称。如果不做修改,则RootFrame找不到MainPage.xaml,还是不停的执行System.Diagnostics.Debugger
Cedar- 已标记为答案 blue601 2011年2月25日 15:21
2011年2月25日 1:33
全部回复
-
判断Navigate方法的返回值
NavigationService.Navigate Method
Windows PhoneNavigates to the content specified by the uniform resource identifier (URI).
Assembly: Microsoft.Phone (in Microsoft.Phone.dll)Parameters
- source
- Type: System.Uri
The URI of the content to navigate to.
Return Value
Type: System.Boolean
Returns Boolean. True if the navigation started successfully; otherwise, false.
Cedar- 已编辑 XuesongGao 2011年2月25日 1:56
2011年2月21日 3:40 -
或者捕获NavigationService.NavigationFailed Event
NavigationFailedEventArgs Class
Windows Phone1/28/2011Provides data for the NavigationFailed event of the NavigationService class and the NavigationFailed event of the Frame class.
Assembly: Microsoft.Phone (in Microsoft.Phone.dll)
Cedar- 已编辑 XuesongGao 2011年2月21日 6:53 update
2011年2月21日 5:36 -
在App.xaml.cs中找到RootFrame_NavigationFailed方法,这个方法是捕获NavigationService.NavigationFailed Event处理页面跳转错误的。
在此方法中添加如下代码,设置跳转错误时转向默认页MainPage.xaml
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
修改后的代码如下:
// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
Cedar2011年2月21日 13:46 -
我晕,又仔细试了下,不行了
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}如果是按着F10,一句一句的走完,页面会卡掉
如果是按F5跳过的话,会一直重复着自动就在 System.Diagnostics.Debugger.Break();中断
2011年2月22日 13:44 -
请尝试升级开发工具集。
2011-2,微软发布SDK的更新包,包含了:模拟器的更新、开发资源的更新、增加了 Capability Detection Tool 、Connect Tool ,以及bingmap control的更新、增加复制粘贴功能等。
下载地址:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=49B9D0C5-6597-4313-912A-F0CCA9C7D277Windows Phone Developer Tools January 2011 Update
Overview
--------------------------------------------------------------------------------Important Installation Instructions
There are TWO separate installations for the Windows Phone Developer Tools January 2011 Update.
Step 1: Follow the link to download WindowsPhoneDeveloperResources_[language]_patch1.msp (Windows Phone Developer Tools January 2011 Update)
Step 2: Follow the link to download VS10-KB2486994-x86.exe (Windows Phone Developer Tools Fix)The Windows Phone Developer Tools January 2011 Update includes:
Windows Phone Emulator Update – Exposes copy/paste functionality in the Windows Phone 7 emulator. For more information, see How to: Test Copy and Paste in Windows Phone Emulator. End users can use the copy and paste functionality only after receiving the corresponding update to the Windows Phone 7 operating system.
Windows Phone Developer Resources Update – Fixes a text selection bug in pivot and panorama controls. In applications that have pivot or panorama controls that contain text boxes, users can unintentionally change panes when trying to copy text. To prevent this problem, open your application, recompile it, and then resubmit it to the Windows Phone Marketplace.
Windows Phone Capability Detection Tool – Detects the phone capabilities used by your application. When you submit your application to Windows Phone Marketplace , Microsoft performs a code analysis to detect the phone capabilities required by your application and then replaces the list of capabilities in the application manifest with the result of this detection process. This tool performs the same detection process and allows you to test your application using the same list of phone capabilities generated during the certification process. For more information, see How to: Use the Capability Detection Tool.
Windows Phone Connect Tool – Allows you to connect your phone to a PC when Zune® software is not running and debug applications that use media APIs. For more information, see How to: Use the Connect Tool.
Updated Bing Maps Silverlight Control – Includes improvements to gesture performance when using Bing™ Maps Silverlight® Control.
WPDT Fix includes:
Windows Phone Developer Tools Fix allowing deployment of XAP files over 64 MB in size to physical phone devices for testing and debugging.
Cedar2011年2月23日 3:27 -
将RootFrame_NavigationFailed的代码修改如下,可以实现当Page不存在时的跳转到默认Page。
其中RootFrame.Navigate(new System.Uri("/Demo;component/MainPage.xaml", System.UriKind.Relative));的代码中,Demo为MainPage.xaml所在的文件夹名称。
请注意在Windows Phone 7中文件都是以相对地址来读取的。
// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}e.Handled = true;
if (RootFrame.CanGoBack)
{
RootFrame.GoBack();
}
else
{
RootFrame.Navigate(new System.Uri("/Demo;component/MainPage.xaml", System.UriKind.Relative));
}
}
Cedar2011年2月23日 5:06 -
将RootFrame_NavigationFailed的代码修改如下,可以实现当Page不存在时的跳转到默认Page。
其中RootFrame.Navigate(new System.Uri("/Demo;component/MainPage.xaml", System.UriKind.Relative));的代码中,Demo为MainPage.xaml所在的文件夹名称。
请注意在Windows Phone 7中文件都是以相对地址来读取的。
// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}e.Handled = true;
if (RootFrame.CanGoBack)
{
RootFrame.GoBack();
}
else
{
RootFrame.Navigate(new System.Uri("/Demo;component/MainPage.xaml", System.UriKind.Relative));
}
}
Cedar
哎,还是不行,如果连接Page的路径有错的话还是如我上次所说问题,一是一步一步调试时,会无限走 System.Diagnostics.Debugger.Break();
二是直接F5会死掉;然后又如世外涛源所说换成Release,俺ctrl+F5会死几秒钟后跳到主界面……算了,碰到类似问题还是仔细检查吧
2011年2月24日 12:56 -
调试时,一直运行System.Diagnostics.Debugger.Break();的原因是异常发生时跳转的默认页面不成功,即在此例中找不到Demo文件夹下的MainPage.xaml。
RootFrame.Navigate(new System.Uri("/Demo;component/MainPage.xaml", System.UriKind.Relative));这段代码需要中修改"/Demo;component/MainPage.xaml",将Demo改为你的工程中的存放MainPage.xaml的文件夹名称。如果不做修改,则RootFrame找不到MainPage.xaml,还是不停的执行System.Diagnostics.Debugger
Cedar- 已标记为答案 blue601 2011年2月25日 15:21
2011年2月25日 1:33 -
-
此讨论问题的源代码下载地址
http://files.cnblogs.com/xuesong/Navigation_Demo.zip
Cedar
嘿嘿,谢谢版主!那个,再问个问题呗……
1:/Demo;component/MainPage.xaml --------component是啥意思?我那个mainpage.xml就是在程序的默认目录,并没发现component目录,难道是指根目录吗?
2:为什么我从MainPage.xaml转到其它页面时如Page1.xaml(和MainPage.xaml同级) 的uri就只写"/Page1.xaml"可以了
2011年2月25日 8:29