(If you’re new to this series I recommend catching up on the first set ofposts here)
In my last post I built out the navigation and history management pieces of the Silverlight browser. In this post I’ll build out the favorites management piece of the browser.
I started off by adding the Silverlight.Navigation.Favorites project to our solution. Here’s waht the project looks like:
All of this is pretty straightforward, and fairly similar to to the Silverlight.Navigation.History project.
FavoriteItem. This represents a single page in the appp that you want to mark as a favorite. It has two properties, a uri (where the thing is) and a name (whatever you decided to name the favorite).
FavoriteItemCollection. A simple ObservableCollection of FavoriteItems. Seriously, that’s it. Nothing more to see here. Move on.
FavoritesManager. This is an abstract class that is responsible for managing an application’s favorites. This class provides mechanisms for adding and removing favorites as well as setting a custom home page within the application. This class also defines abstract Save and Load methods which inheritors are responsible for implementing. The intent of these methods is to read and write to the inheritor’s choice of persistent storage.
IsolatedStorageFavoritesManager. This is a concrete implementation of the FavoritesManager class. As with our IsolatedStorageHistoryManager, this class saves and loads favorites information to and from isolated storage. Real simple.
From a UI perspective, there were really only two things that were done. The first was to implement a Favorites control in our Silverlight.Navigation.Controls project. This is simply a ChildWindow that contains a ListBox which binds to a FavoritesManager FavoriteItems property. I then added a Favorites button to the NavigationToolbar to launch the window.
I also added several buttons to the NavigationToolbar for home page functionality:
- Set as Home Page – this will replace the home page specified by the application map with the current page.
- Use Default Home Page – this will replace the user specified home page with the home page specified the application map.
(In writing this I realized I should have added a Home button, I’ll add it to the features list, which I haven’t created yet.)
The implementation is a snap. I just added a FavoritesManager parameter to the constructor of our Browser control:
I’ve issued a new release on the CodePlex site for this project that contains the functionality discussed above. You can download the release here. I’ve also put this app up on my website here. Per Tim Heuer’s post on Silverlight 3 beta install guidance, I customized the install experience to let folks know if they need Silverlight 3 and what it means to install the beta version of Silverlight 3 at this point in time.
What’s next? Good question, I’m glad you asked. Quite honestly I’m not sure just yet. This entire effort was an experiment to see if it would be possible to provide a consistent UX to both in and out of browser scenarios for Silverlight 3 navigation applications. I think we can call the experiment a success. The next step is to wait until July 10th, when Silverlight 3 goes RTW. At that point in time I’ll update the project to Silverlight 3 RTW runtime and start looking at making these controls into something more “real”, whatever that means.