Well it's my first question here and as far as i searched i didn't find a solution for my problem. I am coding my first rssreader app for WP7 and i am facing a problem with the page state. I have 3 pages and navigation goes like that
mainpage >>> listitemspage >>> detailspage. Mainpage is a databound model with preconfigured feeds category items (urls and names), listitempage is a page in which i implemented a webclient to read feed items and detailspage is where i pass the details of the selected feed item from listitempage. Page state working in these situations:
mainpage >>> start button >>> back button (OK)<br/>
listitempage >>> start button >>> back button (Doesn't work)<br/>
detailspage >>> start button >>> back button (OK)<br/>
In detailspage i save the page state using OnNavigatedTo/From and State.TryGetValue
This seems to work but if i create a button with a browser task so the user can navigate to the full article when the browser open and user press back button the details page state works. If the user press for second time the back button then the app is exiting instead of navigating back to the listitempage. So i have this problem too:
detailspage >>> browserbuttontask >>> backbutton >>> restorepage >>> backbutton->exit<br/>
Any ideas?
I'd recommend using the Tombstone helper on codeplex written by Matt Lacey (of the Windows Phone User Group).
http://tombstonehelper.codeplex.com/
It will either solve all your problems very easily or at the very least show you how to write your page states off to isolated storage for long term use (remember the state cache only survives while the device is powered and so long as the phone doesn't need to clear it's memory)
Hope this helps
Rgds
Simon
If you want to save page state without messing with IsolatedStorage try SterlingDB. It uses IsolatedStorage but it is very simple to setup and use. You can add sterling via nuget. You will have to stick data you want persisted in a class but saving and loading is simple.
Beyond that you also might want to look at Caliburn Micro. It adds page lifecycle to your ViewModels like OnInitialize, OnActivate, OnDeactivate. It also adds some nice stuff for WP7 like automagically persisting properties on a ViewModel to IsolatedStorage or phone state.
http://www.sterlingdatabase.com/
It sounds like your application is throwing an exception when restoring state to your list page, which has the effect of terminating the application.
Have you tried doing all this with the debugger attached? It should show you what exception is being thrown and where.
Related
Hi I have this hierarchy
App (RootFrame)
Login Page
Main Shell (InnerFrame)
List Page with entities 1
List Page with entities 2
Detail Page for entity 1 (InnerFrame2)
subpage 1-1
subpage 1-2
Detail Page for entity 2 (InnerFrame3)
subpage 2-1
subpage 2-1
And I want to handle Back button correctly. Navigating between pages in inner frames is ok, but when I go for example from "List Page with entities 2" to "Detail page for entity 2" and then back, MainShell i recreated and forgets the InnerFrames BackStack and opened Page(should be "List Page with entities 2")
Is there any elegant way to handle this? for example save InnerFrames history and current page when navigatedFrom at MainShell happens?
You can try Prism Framework, here is a lifecycle managing example.
In a nutshell Prism provides SessionStateService to manage view restoring when OnAppSuspended and OnAppResumed events invoked.
Also Prism NavigationService passes NavigatedToEventArgs e, NavigatedFromEventArgs e, Dictionary<string, object> viewModelState parameters and your page behaviour can be overrided in OnNavigatedTo and OnNavigatedFrom using this parameters.
I found what I needed. There are SetNavigationState(string) and GetNavigationState() methods on Frame object. Thanks anyway
I'm creating a web browser. On the "mainpage" it has a button that takes you to the homepage, i'd like to give the user the option of changing the home page on "page1" (settings). on page1 I have "textBox1"(where the user enter desired homepage) and "button1" (set). Could you help me set this up? Is there a way where doing that action can change the source of webBrowser1?
First I would suggest you to download this Programming Windows Phone 7 ebook and explore it to learn Windows phone programming before asking StackOverflow.
Coming to your question,
Create a Settings class in the project and Add a static string property named something like "HomePageUri". Then in your Page1, add the source uri to that "HomePageUri".
Then in your main page, in the OnNavigatedTo event update the WebBrowser's source or you can bind the WebBrowser's source directly to the "HomePageUri" property
Good luck
I'm developing a Windows Phone application and I have three screens:
Main screen
Login selection screen.
Sign in screen.
When user has signed in and push "sign in" button I want to come back from screen 3 to screen 1.
Now I come back to screen 2 and immediately to first one. I don't want to show 2 screen.
Is it possible to do this?
Try this
Assume your pages are named as FirstPage.xaml, SecondPage.xaml, ThirdPage.xaml
//Check for the first page and remove the remaining back stack in your ThirdPage.xaml
while(!NavigationService.BackStack.First().Source.OriginalString.Contains("FirstPage"))
{
NavigationService.RemoveBackEntry();
}
NavigationService.GoBack();
Somewhere in page 3 add
NavigationService.RemoveBackEntry();
This will remove page 2 from the back stack. Now when the user hits the back key, he'll navigate directly backwards to page 1.
But as Amal Dev noted, Microsoft wants you to let the user navigate to the previous page. This rule doesn't seem to be enforced too much, it's probably meant as "never ever confuse the user". If you confuse the certificating tester, your app will fail certification.
You can use the NavigationService.Navigate method for this.
NavigationService.Navigate(new Uri( string.Format("/your page name.xaml?val={0}", ValueTextBox.Text), UriKind.Relative));
Please refer the link given below.
Simple Navigation In Windows Phone 7
I recently started working on a project that has been in development for some time now. The problem is this - in the web site page, a have a frame (amongst 4 others) in a frameset which contains the SVG map object (the whole site is GIS based). Also, in the same frame, there is a icon for opening the form in which user can choose a number of filters, and after he presses a button, the map refreshes and the area of influence around some key points on the map are drawn.
What i need to do is to open that form in a new (popup) window and not in the same frame where the map is. I did that this way:
onclick="window.open('zi.aspx','form1','width=700,height=500,left=350,top=100')"
This works fine. But then, when i enter the filters and hit Generate button, i get this error:
'parent.frames.map' is null or not an object
with the reference to zi.aspx. Now i know that this error is because i changed the form from opening in the same frame as map to opening it in a popup window, but i just can't find anywhere in the code where can i modify it. Before my changes, the code was just this:
onclick="showZi();"
and that is the function i can't find anywhere. Any ideas? How can i make this work, to make a map with filters drawn after the user has chosen appropriate ones from the popup window form? I should mention that this image link is in the ASP.NET table, with standard runat="server" command.
Okay, so you're opening a new window from javascript. Your problem is that you're trying to access the parent window by using the 'window.parent' property. This is wrong, you'll need to instead use 'window.opener' property. E.g.:
window.opener.frames.map
I have a simple Silverlight application that consists of four pages (XAMLs).
Navigation is done by calling:
//from XamlPageA
this.Content = new XamlPageB();
Is this the right way. I need to have the entries in Browser history so that users can go page to the previous page(s). How can I do it.
You are bypassing the navigation system completely by setting content manually. You would have to implement updating the browser history yourself if you do it that way (certainly possible, but quite tedious).
A simpler approach is to generate a "Silverlight Business Application" project and see how the page navigation is simply handled with hyperlink buttons. All the browser history plumbing is done for you as is the mapping from URL to views.
e.g. A button with NavigateUri="/Home" will cause a view named Home.xaml to load into the navigation:Frame of the MainPage window.
if you look into the navigation:Frame element of MainPage.xaml, you will see a number of UriMapping entries like this:
<uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
They provide the pattern matching to convert from URLs to views.
Hope this helps your project.