Deep linking in Silverlight application
September 3, 2009
Often you want to do deep linking in Silverlight without going the whole hog and using the new Navigation Framework. Not that the Navigation Framework is bad, but it does impose a architecture on your application that you may not want to follow.
Instead you can use the HtmlPage.Window.CurrentBookmark to store an arbitrary string. This will change the address in the browser by appending the string as a hash code or anchor. This is great as you can now bookmark the URL by hitting Ctrl+D. Only problem is if a user selects a bookmark while you application is still running then there’s no obvious way to detect the change.
HtmlPage.Window.AttachEvent(“onhashchange”, new EventHandler(OnHashChange));
Works like a charm!