The team blog of the Expression Blend and Design
As many of you know, MIX is Microsoft’s design-focused conference held in Las Vegas near the beginning of each year. Last year, the focus was all about Silverlight 2. Looking through the list of sessions posted so far, the buzz seems to be around Silverlight 3.
A group of us from the Expression Blend and Design teams will be there, so if you are going to be in the Venetian, feel free to drop by any of the Expression sessions and chat with us. We would love to hear from you.
If you are undecided on attending, there is a discount if you register by February 14th, so click here.
Cheers! Kirupa :-)
As you know, Visual State Manager is a Silverlight 2 (and WPF Toolkit) platform feature that makes it easy to define a control’s visual states and to perform the transitions between states. In the case of a templated control (such as Button, CheckBox, etc) you need only fill in the states advertised by the control (using Blend’s States pane), and the control itself will take care of performing the transitions at the right time. But if you’re writing your own UserControl then you need to add your own states to the control and you also need to know how to handle events and call VisualStateManager.GoToState() to transition between your states. Attached to this blog post is a base class that I hope will get you off to a good start. Basically you can derive your own UserControl from this class and override some methods and hopefully that will have saved you some work.
First, download and extract the StatefulUserControlBase.cs source code file from the following location:
Once you’ve downloaded and extracted the source code file (StatefulUserControlBase.cs) you can try out the following steps.
public partial class CheckBoxUC : BlendHelpers.StatefulUserControlBase
CheckTwoStatesEnum _checkState = CheckTwoStatesEnum.Unchecked;
// Required to initialize variables
protected override void UserControl_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
_checkState = (CheckTwoStatesEnum)(1 - (int)_checkState);
protected override void UpdateState()
You now have a functioning two-state checkbox in the form of a UserControl. All you need to do next is to define the states as you would for the built-in CheckBox control. Naturally you won’t want to reproduce the built-in controls with your own UserControls, but now you know how to extend the base class you’ll be ready to do something more practical.
A completed sample is also provided.