A Browser History Example

Using the techniques you've just learned about, you can tackle a true Silverlight challenge— integrating your application with the history list in the web browser.

Ordinarily, Silverlight content exists inside a single page. Thus, no matter what takes place in that page the browser history list never changes. This can confuse users, who often expect that clicking the back button will bring them back to the previous visual in your Silverlight application, whereas it will actually end the current Silverlight application and bring them to the previous page.

Flash applications and HTML pages that make heavy use of Ajax features face the same problem. There are several known workarounds, although none are simple and many have subtle compatibility issues that prevent them from working with certain browsers. In this example, you'll see a reasonably robust solution that works with recent versions of Internet Explorer and Firefox. However, if you decided to use this code in a real-world application, you'd need to test and refine its code more thoroughly to make sure that it doesn't cause problems on less common browsers.

Tip There are several Ajax libraries that offer history list solutions. If you use one of these in other web development, you can probably integrate it into Silverlight uses the techniques explained in this section. Also, future versions of ASP.NET will include an Ajax-powered history management feature, which can also be adapted to work with a Silverlight application if you're hosting it in an ASP.NET website.

In the following sections, you'll study the solution piece by piece. Figure 12-8 shows the final result, in a simple application that allows you to move through a sequence of pages. On the left side, the user starts on the first page. After clicking ahead twice, the user moves to the third page. The browser history list shows the page names and allows the user to jump back to an earlier point.

Figure 12-8. Showing Silverlight pages in the browser history list
0 0

Post a comment

  • Receive news updates via email from this site