问题
What kind of navigation is best suited for a home button in an application,Can any please help me,I am newbie?
回答1:
Updated Answer based on your comments, First you need to create a button(preferably an Appbar button) and then place this code in the click event handler
NavigationService.Navigate(new Uri("/Home.xaml?home=true", UriKind.Relative));
And then in the Home page in the onNavigatedTo
event handler place this code
string home;
NavigationContext.QueryString.TryGetValue("home", out home);
if(home != null)
{
if (home.Equals("true"))
while(NavigationService.CanGoBack)
NavigationService.RemoveBackEntry();
}
So this clears all your back stack
Note: This is not any preferable or recommended way, its just a workaround!!
回答2:
Add a button in every page (since you want to go home from every page) put the onClick to do:
NavigationService.Navigate("YoursView/HomePage.xaml", UriKind.RelativeOrAbsolute);
回答3:
You may want to review the following MSDN documentation regarding Application Structure and Navigation Models :-
http://msdn.microsoft.com/en-us/library/hh202909(v=vs.92).aspx
回答4:
This worked.
Globally I declared a Boolean variable set to false in a class.
Then whenever the home button is clicked bool variable is set as true and navigated back.
Modules.HomeClick = true; NavigationService.GoBack();
Then in every page for page loaded event I checked condition if bool variable true go back.
if (Modules.HomeClick=true) this.NavigationService.GoBack();
these done in every page till homepage.This do not store backstack.
来源:https://stackoverflow.com/questions/11187944/navigation-in-windows-phone7