Default Form Button Behaviours for Silverlight

Behaviours are a great way to encapsulate useful functionality in a self-contained object. These objects can be attached to XAML elements in a Silverlight page to enable features that the elements do not themselves contain or know about.

A feature present in Win Forms and missing from Silverlight is the concept of Default Submit and Cancel Buttons. That is: a button that is clicked automatically when Enter or Escape is pressed while entering  text in TextBox controls on a form.

Type text into any of the 3 TextBox controls below and press the Enter key to “submit” the form or the Escape key to “cancel” the form. For test purposes random numbers appear under the buttons to show that the button actions have been fired (you can just press the Go or Cancel buttons directly to see this).

Install Microsoft Silverlight

The example above uses our new DefaultButtonBehavior and CancelButtonBehaviour. The features are:

  • Can be attached to single text boxes, or to entire forms.
  • Can be enabled independently of the text boxes (this property is bindable).
  • Can ignore empty text boxes (this property is bindable). This is useful for single text box user controls, like a search box.
  • Automatically presses and releases the target button, based on the Enter or Escape key press and release, to give good visual feedback.

We have released this behaviour  to the Expression Gallery. Feel free to download and try it out. Feedback and suggestions welcomed!

Stack Overflow: All quiet on the Silverlight front

We’ve been on for about 5 weeks now. One of the things we have noticed is a relative lack of traffic on the Silverlight tag/area when compared to other more common subjects like C#.

One positive result of the low traffic, is that today I was awarded a Gold “Unsung Hero” badge:
Unsung Hero!

Swells with pride… until you realise: that means at least 25% of 150 or so answers have been marked as “the answer”, but nobody has up-voted them as “useful”.

Luckily we are just there to learn and teach. The ranking system is a nice touch, but if anything seems to lead to a rush of poor answers. People compete to earn points and focus more on speed and less on good content.

Still a very worthwhile place to hang out (for computer geeks anyway) :)

Cheers, Dave

Silverlight Control Inheritance Tree

Here is another trivial app. The interesting feature is that it is hosted in a ViewBox control, so resizes to fit the Silverlight control in this page:

Install Microsoft Silverlight

Using the ViewBox as a visualroot container

The same ViewBox based Silverlight control is reused here with a 100 by 100 size:

Install Microsoft Silverlight

The ViewBox control is a very cool addition to control top level scaling of Silverlight apps.

Silverlight plugins for WordPress – practical example

This is a test of the Silverlight Plugin for WordPress by Tim Heuer. Move your mouse over the Silverlight control to start additional animation.

Install Microsoft Silverlight

Documentation was a bit light on the ground but a Google cached copy of Heuer’s blog page revealed the required parameters. The trick is to place your Silverlight component’s XAP file into the root of your blog website (it was not specified, but we figured out this by watching the http requests with the Firefox Http Headers adding).

The widget injects all the require Javascript for you. The WordPress widget marker syntax (inside square brackets) is:

silverlight: <app>, <width>, <height>, <initParams>, <minVer>

The parameters are:

  • app is the XAP filename
  • width is the display width of the Silverlight component (optional)
  • height is the display height of the Silverlight component (optional)
  • initparams maps to the initiparams of the Silverlight component (optional)
  • minVer maps to the minRuntimeVersion required for your app (optional)

Cheers, Dave

WordPress Themes