I am designing a Windows 8 Metro reading app, and got a problem of navigation event at the right begining. To simplify the problem, the description is:
There are two Pages: MainPage.xaml and DetailPage.xaml. MainPage.xaml contains a listview, the item is an article object(thoses article items are downloaded from the web), the a item is clicked. The Frame will uses
void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
// Navigate to the appropriate destination page, configuring the new page
// by passing required information as a navigation parameter
this.Frame.Navigate(typeof(DetailPage), e.ClickedItem);
}
After reading the full article, user will clicked the “GoBack” button, which is defined as
<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
Then the problem comes, it’s supposed that the Frame just navigated back to the MainPage, but after the navigation, the DataContext in the MainPage is missing, and the construction function of the MainPage is called again, fetched the web resource.
As a Windows Phone developer, I’m confused about this problem. Could anybody help me.
Thanks in advance.
The default behavior specified by Page.NavigationCacheMode in WinRT/XAML is different than in the PhoneApplicationPage on Windows Phone. It defaults to NavigationCacheMode.Disabled, while NavigationCacheMode.Enabled or .Required is what you probably want to use to make it work as expected.