Each XAML page's code-behind file contains the following method definition:

public static Uri CreateNavigationUri(…)

Additionally, all query parameters are defined as constant static values in the class.

I believe this is a useful pattern the following reasons:

  1. If you change the name of the page or move to a different location then you only have to update this method to change the link (you could modify the method do get the name of the page using reflection, but it seemed like overkill and could make it complex when you have to include the path too)
  2. You can control the values being set on your parameters (this does not enhance security though, it's just a developer aid).  For example: if I have a Boolean parameter, like above, then my caller doesn't have to work out whether the value should be: "yes", "y", "Y", "Yes", "True", "true", "TRUE", etc.
  3. You only have to remember to URL-encode your parameter values once for this page, rather once for each page linking to this one.
  4. When coding links to the page, Intellisense tells you what all the available parameters are and what they mean.
  5. By using constants for the query parameter names, it makes it safer to extract them in the destination page's execution; get the parameter name wrong and you'll get a compilation error.

Last edited Nov 1, 2012 at 8:34 AM by AndyBrodie, version 1

Comments

No comments yet.