OK so I finally found some time to start playing around with SL2 B1 in earnest this last weekend.  The results? A Silverlight Calculator.  I don’t know why but a calculator has always been my HelloWorld, every new programming language or UI stack I learn always starts with a calculator.  Anyway you can try out the live version of it here and download the full source code here.  You can find some good instructions on how to get up and running on Silverlight here if needed.

A Basic Calculator

Default Calculator Skin

 

A quick overview of the things I explored during this process.

  • The wonderful world of styling controls in Silverlight.  Have a gander at BasicBlack.cs and generic.xaml to see how I set up the styling for my basic calculator skin.  CalculatorAddIn/GlassSkin.xaml shows an example of a new skin over the basic template.
    Glass Style
  • Skinning is also supported, you can rip the entire UI off the calculator and replace it with your own as shown in CalculatorAddIn/SimpleConsole.xaml & .cs.  To support this skinning approach I had to achieve a simple View/Model separation in the code through the use of interfaces (see ICalculatorEngine.cs, ICalculatorCommand.cs and INumericStack.cs).
    Simple Console Skin
  • Support for custom AddIns.  I wanted to let folks write their own calculator functions in addition to creating their own skins.  Checkout App.xaml.cs and CalculatorFrame.xaml.cs for all the code behind loading assemblies on the fly using AssemblyPart.Load().  You can try this on your machine by downloading the ZIP file for the code and selecting the CalculatorAddIn/ClientBin/CalculatorAddIn.dll when the Open Add In dialog opens.
  • IsolatedStorage – interesting concept for remembering what AddIns have been loaded when you come back to the web page.  IsolatedStorageFile.TryIncreaseQuotaTo() is an interesting API to say the least!

Some known issues/ToDos:

·         Resetting the AddIns is a fairly jarring experience right now (since Assemblies cannot be unloaded, a full page refresh is done to cycle the AppDomain).  At a minimum I need to have an Are you sure? MessageBox (but SL has no such thing yet).  Ideally you should be able to turn off the add-ins one at a time and the calculator would just quit using the extension even though they still exist in the domain.

·         No versioning support for the AddIns.  If you want to get a new version of your AddIn loaded you currently have to unload all the AddIns, reset the AppDomain and then reload your addins.

·         Application Errors are either ignored or unhandled right now.  I have to figure out a good model for dealing with these things.

·         Currently only text is supported in the Command Buttons, I need to explore the wonderful world of loading/parsing XAML at runtime and allow commands to have more sophisticated button views.  Styling is currently putting a serious crimp in these efforts, but we’ll see where it goes.

Anything else?  Comments?  Ideas on additional areas/techniques to explore here?