A Customer who asked if a quiz-type application can be enabled by Silverlight.
The answer is yes (obviously
) and I had to put my rusty coding skills to work over a good part of a Saturday afternoon.
The result is a Silverlight 1.0 proof-of-concept application, which meant adopting an "AJAX-styled" coding model with JavaScript. In fact, just for the heck of it, I wanted to go the full client-only approach which meant no ASP.NET AJAX server-side controls, etc.
The code demos a couple of simple features:
- Quiz questions are easily configurable with a XML data file. The Silverlight application accesses the quiz as JSON data with a simple web service. This was simply achieved by first converting the XML data to JSON format at the server-side with XmltoJSON C# code (made available at http://www.phdcc.com/xml2json.htm). To allow the web service to be accessible (invoke-able) by the client JavaScript, I also marking the web service with the System.Web.Script.Services.ScriptService attribute.
- An auto timeout (set to 10 seconds) is set for each quiz, this is done with a XAML animation storyboard to mimic a timer. Jesse Liberty details this useful technique in his blog here.
- At the client end, I dabbled a little with the JavaScript Prototype library to demonstrate interaction between the Silverlight application and the host browser's DOM.
The application can definitely do with polishing (e.g., with some creative design work, one can imagine fireworks animation when the user gets a correct answer,) but this should serve as a nice simple base for extensions, tearing apart, etc.
Links:
- The source code is available for download at my SkyDrive here.
- The application can also be viewed online here.