Doubts regarding handling the state of pages in Wp7 Phone App - windows-phone-7

I have the application ,in which i save the state of the page and while deactivate the application,and once i get in foreground the application,i will restore the data.But when i click the back button at the time,i don't have the Object instance for the previous page .So how can i handle at that time?
On BackKey Press,I need to some thing like
1)Check the pages in the stack,remove the previous page and create the new instance of the page or any other think?

Your data should be saved when your application is deactivated and reloaded when your application is restored. It sounds like you are not restoring your data correctly.
This is where using something like MVVM model where your data is separate from your UI code is really helpful. Check out the MVVM light toolkit on CodePlex.
http://mvvmlight.codeplex.com/
It is too general a question to give more specific answers than that. Sorry.
Try coding up something and posting specific questions regarding your code.

Related

Implementing shake to go home Functionality

In my application client had a requirement that. When the user shakes the phone he/she should navigate in to the home page. So writing the shake event handler in each page seems bit difficult. Is there any way present to handle this event in a single page like app.xaml, if any one go through similar situation and found a solution please help me too for achieving the functionality
For shake detection you should use accelerometer like described in this article. For presenting it to all pages, you could use
RootFrame
property in your app.xaml.cs and call it's Navigate property when the shake is detected.

Selective Virtualization in WP7 Listbox with VirtualizingStackPanel

I am referring an app like Facebook WP7 app. When we try to scroll a long list of the feed items. Only the heading of an feed item seems to be visible and when the scroll is completed remaining details gets loaded. If it is a normal Listbox where virtualization is enabled complete data disappears and all the controls seem to be recycled. So in facebook app, I thought that the virtualization is happening on selective items. Am I right?
If yes, how to do a selective virtualization? and if I am wrong what is the app exactly doing? Any resource regarding this will be helpful.
Thanks in advance.
I believe that this is just how their data binding works.
They get an initial list that contains the "headers" and some basic information, which they show. They then make more calls to grab the rest of the info. When that info comes in, it updates in the view model and thru databinding shows up on the list.
I have apps that do that, and they behave similarly to how FB's listbox behaves.
As Willmell pointed out, this msdn link describes what Facebook is doing exactly. The template of the listBoxItem will be switched while scrolling.
Try to look here. This guide helps me to solve a similar problem.

Windows Phone Application - Start page depends on FileExist in isolated storage

I'm developing application that start page depends on file existing in isolated storage.
If file doesn't exist my application shows some form to setup configuration, but if it exist I wish this page will not be diesplayed.
For now I just load configutarion page but if file exist i use NavigationService to navigate to proper page on pageloaded event. The problem is that after I play with my app and hit back button it goes to configuration setup and because file exist it navigates me stright to my app again. I despite the fact that setup screen blinks on the application launching.
So my question is - how to setup startup page depends on some condition ?
The advice that I've heard is to use a UserControl on your startup page - then toggle the visibility depending on the condition you have. That way you don't end up with an unwanted page in the backstack and you get to fully control the UX.
The example I heard it with was a login page - not something you want on the backstack usually - but something you can easily check a bool to hide/show the user control.
The place I heard it was this video from Mix 11: Expert Lessons: Top Tips for Building a Successful Windows Phone Application. You can download the code to the demo (it is the first demo in that video) from the bottom of his blog entry here (which gives some more detail): Demos from my Mix 2011 session - Part 1: Navigation Tips
There is no way to launch different page on some conditions.
There are methods to manipulate Page Stack in NavigationService class, so you can remove setup page from history and app not will be navigated to it when user tap back button.
For fighting with page blinking you can put an image (the same image as splashscreen) above your page, and hide it when right content loaded

How to implement slide in/out view with controls in WP7?

I am new to windows phone (WP7) and to me it looks like everything on WP7 is about pages. I want a small window to pop up from the bottom of a page while staying on the same page. The small window will have some controls (like slider, list etc.). It should not behave like a modal dialog box though, i.e. the rest of the page (which is not covered by the small window) should still be active and user should be able to do something there. And I want to have a separate C# class which will handle the events from the controls on the small window.
This is very easy on iPhone, using view controllers, is there something similar on windows phone?
It sounds that it would make sense to make your "pop up" part of the page with the content it is intended to manipulate content on that page. If you want to encapsulate the functionality of the "pop up" you could make it a UserControl. If you went this route then animating it to slide onto the screen will be straightforward.
Windows Phone 7 typically uses an MVVM model compared to iPhone's MVC one for app structure. The direct comparison therefore isn't appropriate. WP7 also uses a very different design language to that of the iPhone and so a straight port of application design and layout is also unlikely to create a great experience on WP7.
I'd recommend taking some time to understanding the differences in the platforms and how your existing design would be best suited to recreation on WP7. Not only will this help you create a better experience on WP7 but enable to see if this your question actually relates to something you should be doing or not.
This very much sounds like something that goes against the nature of the platform, and the general design guidelines.
If you're providing some available configuration options to the user, you should do it on a separate page, so the user can change the settings there, approve it, and then be navigated back to the previous page.
However, if you really want to, you're talking about displaying a UserControl inside a Popup. But it wouldn't be a very good user experience, and confuse most users, as it doesn't follow the same look&feel as the rest of the platform.

Navigation & Tombstoning - Best Practices

I'm just learning about how to navigate between pages and tombstoning. I'm wondering if anyone can point me to some good examples that not only show me the basics of how to use Navigation properly but also good examples of more complicated and advanced navigation issues?
Some questions I have revolve around memory leaks when navigating to other pages and navigating back?
Is there a close page call, once the page has done its job (I don't want an instance of it hanging around after I'm done with it)?
Another question is how to I maintain state if the app gets tombstoned (still trying to wrap my head around that term).
Thanks!
There's no close page call, the OS automatically closes pages when they're backed out and releases used memory (so there should be no leaks here).
Some resources here that cover tombstoning and advanced navigation concepts.
Understanding the Windows Phone Application Execution Model, Tombstoning, Launcher and Choosers, and Few More Things That Are on the Way – Part 1, Part 2, Part 3
Introducing the concept of “Places” - Peter Torr's Blog
Redirecting an initial navigation - Peter Torr's Blog
I like thinking about WP7 navigation like a simple browser that only have back button. The Naviation model is based on stack pattern (Last In First Out), need to get through all to get back to first page. This is not what PC user are used to but in mobile world is one of the best solution.
You have to stick to this model and never ever do "go to home page" button - your app will not pass the certification for sure(there are some workaround with excetions but I wouldnt recommend that).
A lot of pages can get the user pissed that's why a good idea is to have 3 to 5 pages max. For instance, first page user picks what he is going to do, next page is login page and then for more complex interface use panorama and pivot control.
To the simple browser model add cookies. When your browser load a page it sets a cookie with some information, next you close the browser and when you go back to the page it can get the previous state from that cookie. Tombstoning is very simailar. - link. Some more info about tombstoning
Some questions I have revolve around memory leaks when navigating to other pages and navigating back?
What do you mean by memory leaks? you are working in managed framework.
Is there a close page call, once the page has done its job (I don't want an instance of it hanging around after I'm done with it)?
you do not have to do this. Page is destroyed everytime you go to the next page unless a thread is still working there.
Another question is how to I maintain state if the app gets tombstoned (still trying to wrap my head around that term).
Basically it's up to develepor to manage this. It is not mandatory but gives a nice user experience.
Another question is how to I maintain state if the app gets tombstoned (still trying to wrap my head around that term).
Use Isolated Storage.
You can have a look into Columbus MVC framework for WP7 source code (http://columbus.codeplex.com/) that I have published recently. Columbus addresses both Navigation and Tombstoning (provides strongly typed navigation with history and View Models that can survive tombstoning).

Resources