During WP7 app development, page Jump is another common operation. It can be implemented in XAML and implemented using navigationservice In the CS file behind the XAML, however, after using mvvm to develop models, viewmodel is not as intuitive as the previous implementation.
In fact, it is very easy to implement page Jump in viewmodel. The followingCode:
Using Microsoft. Phone. controls; var root = app. Current. rootvisual as phoneapplicationframe; root. navigate (New uri ("/nextpage. XAML", urikind. Relative ));
Under normal task circumstances, these lines of code can be completed, but there is a problem, let's further discuss: to create a user login function, according to the normal business process, after the user enters the user name and password on a page,ProgramThe connection server verifies the user's validity (this process requires network connection, which may take a long time and is asynchronous). After the server returns data, if the user is a legal user, the program jumps to the user's personal information interface. Otherwise, an error message is displayed.
The code for selecting behavior after viewmodel processes the data returned by the server should be as follows:
If (result. issuccess = true) {var root = app. current. rootvisual as phoneapplicationframe; root. navigate (New uri ("/userinfo. XAML ", urikind. relative);} else {// displays error information. }
However, to connect to the server, you need to connect to the network. If the network signal is poor, You may click "Log on, after 10 seconds, you will not receive any success or failure prompt (a "Logon in progress" may be displayed if you have a better experience "), the user is impatient and presses the back key or other operations to enter another page. Suddenly, after the server's feedback data is returned, the viewmodel code above forcibly brings the user to the personal information page, so, the user is very angry, and the consequences are very serious.
Just add a judgment:
If (result. issuccess = true) {var root = app. current. rootvisual as phoneapplicationframe; If (root. currentsource = new uri ("login. XAML ", urikind. relative) root. navigate (New uri ("userinfo. XAML ", urikind. relative);} else {// Display Error information}
(In addition, it was found that the text in the blog garden was badly collected by other sites, and many sites did not write any source. for reprinting, please indicate the source ~ Http://www.cnblogs.com/vistach)