Working with Page Sessions

Windows Media Center includes a true page model that provides the ability for pages that were authored in MCML to persist their state and discern between navigation direction (forward or back in the page stack and history). When a UI is navigated away from, the UI and all the visuals associated with it are destroyed. However, the URI of the UI and all the property values passed to the UI are saved. When the UI is reloaded (when the user presses "back"), the UI will be recreated and the persisted property state of the UI will be used during the initialization. It is important to place any data that should survive between page navigations in the UI properties. All other state (such has locals) will be discarded when a page is put on the backstack.

  • The PageSession.OnNavigate method is called when the NavigateCommand element is invoked in the application. The parameters from NavigateCommand are passed directly to this method.
  • The Environment element tracks the state of the current host and includes attributes containing information about navigation, allowing your application to respond accordingly: IsNavigating indicates whether the user is navigating, and NavigationDirection specifies whether the user is navigating to the current page or away from it.
  • The Page.PushOnStack property lets you specify whether a page can be placed on the backstack or should be omitted from it.
  • The Page.State property lets you get a collection of properties and values for the current page, allowing the application to pass application-defined parameters to a newly-created page.
  • Applications can determine whether the page is currently the active page that is being viewed by the user by checking the ApplicationContext.IsCurrentlyVisible property.

Sample Explorer

  • Page Navigation > Navigate and NavigateCommand
  • Page Navigation > HistoryOrientedPageSession
  • MediaCenterEnvironment > NavigateToPage

See Also