Question

Every Windows Phone developer might be familiar with the NavigationService and the way a URI is used to navigate to the specified content, i.e.:

 NavigationService.Navigate(new Uri("/Views/DetailsPage.xaml?selectedItem=" + selectedItem.ID, UriKind.Relative));

But is there an explanation for WHY it is this way?

The issues about the safeness when using it are:

  • If you rename/move/refactor a class, the URI won't work anymore. Same with properties.
  • You have absolutely no validation if the specified Page or the Properties exist
  • Even though this is the standard mechanism for page navigation, why doesn't the IDE at least validate relative URIs to check if the classes and properties fit?
  • Why doesn't anyone seem to care?

Compared to e.g. Android and iOS, both provide at least more type safety, or am I missing something here?

Was it helpful?

Solution

The explanation is quite simple: Silverlight.

Silverlight implements an URI-based system for obvious reasons: the framework has been designed to be executed inside of a web browser, and therefore it makes deep-linking easier to implement (that is: opening a specific page of the Silverlight application depending on the requested URI in the web browser).

Windows Phone's runtime is based on Silverlight, so the same system simply remained. Note that it isn't a bad thing. Sure, if you stop at the navigation service, it looks like we're losing type-safety for no benefit. But if you consider that your application can be launched from a secondary tile, or since WP8 from a custom URI scheme, it suddenly all makes sense.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top