March 2008 Entries
The question of calling JavaScript functions from Silverlight seems to come up quite often and there are solutions to the problem. But one answer I have not seen yet is to use the HtmlPage.Window.Eval method. This method is simply a pass-through to the Eval method in JavaScript on the browser end. It might not be an appropriate solution in all cases, but it's always nice to have options! 1: // C# Code
2: HtmlPage.Window.Eval(string.Format("doSomething('{0}');", "hello there!"));
...
One nice feature of Silverlight is the ability to load resources from the server at runtime. For example, suppose your application needs to display text in a specific font. Ideally, your code would call out to the server (using WebClient) to pull these resources only as they become necessary. The cool thing is that you can zip up any resource you have and then extract it for use on the client side. 1: WebClient webClient = new WebClient();
2: webClient.OpenReadCompleted +=...
If you have done any work with the controls in the Silverlight beta, you may have noticed the absence PasswordBox. I posted a question in the forums asking for this functionality and the current word from Microsoft right now is that it might be included in the final release, but no promises. Until that day, there are alternatives. You can write your own, or you can use the one written by Chris Pietschmann. Enjoy!
Now that we have the XAML UI complete on our color picker (live demo here), it's time to wire up the control with some logic. To spare you the boring details, this post is really just a summary of the key pieces of logic. Obviously you can download the complete source code, and if you have any questions, please feel free to send me feedback!
As a first step, we need to make the selectors responsive to the various mouse actions. The hue selector on the left side of the control responds to mouse dragging and clicks in the Y direction. ...
When customizing Silverlight controls, there are several techniques you can follow. Each technique provides a varying level of control and development effort. If you want to change the layout of any of the built-in Silverlight controls, you will generally need to work from the existing default template contracts as a starting point. So where are these template contracts? Currently, there are two places you can find these templates: SDK Documentation The SDK documentation contains a subsection called Control Styles and Templates. In this section, you will find the default XAML template contracts for...
Before Silverlight 2, one had to conjure up various hacks to emulate a Timer. One the most popular hacks was to use a StoryBoard that would continually call upon itself after completion. This would end up looking something like the following: 1: public partial class Timer : UserControl
2: {
3:
4: public delegate void TimerFiredHandler();
5: ...
With the release of Silverlight 2, a new set of standard controls have been introduced. Kathy Kam has built a nice sample that shows off these controls. Below are a few key points that I took away from watching Scott Guthrie's Silverlight Keynote: Controls are open source Unit tests for controls included Unit test framework for testing UI and non-UI functionality included More controls from Microsoft on the way DataGrid and DatePicker controls included Control layouts can be changed using Templates...
Internet Explorer 8 - Beta 1 was unveiled today at Mix08. If you want to try out Internet Explorer Beta 1 without tainting your system, check out the Internet Explorer 8 - Beta 1 Virtual PC images. The current image expires on July 3, 2008. http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&displaylang=en
Silverlight 2.0 Beta 1 has just been released just before the start of Mix08. Enjoy! http://silverlight.net/forums/t/10586.aspx http://msdn2.microsoft.com/en-us/library/bb404700.aspx
There are a few cases where you need to create many similar objects from a single XAML object definition. For example, say you were building a chess game in which each square was represented by a Rectangle primitive. You have several options here: Create 64 Rectangles in XAML - Terrible! This option is terrible for several reasons. First, you will have an enormous XAML file to maintain. Imagine what a nightmare it would be if you had to change the look of the squares! Second, you are violating the DRY principle. I could go on,...
ASP.NET Jon Galloway - Getting JavaScript and ASP.NET talking (outside of AJAX) Rob Conery - SubSonic 2.1 Beta is Up Mix '08 Sessions MVC Framework Jeffrey Palermo - ASP.NET MVC in Action - An accelerated introduction to the ASP.NET MVC framework. Mike Bosch - Submitting and AJAX form with jQuery JavaScript and AJAX Rick Strahl - Embedding ASP.NET Server Variables in Client JavaScript - Part 1...