Geeks With Blogs
Imran Shaik Silverlight Quintessential Rambling

In Silverlight 2.0/Expression Blend 2 SP1 creating a new VSM state was pretty straight forward, either for a UserControl or Custom Control a new Visual State could have been created by just clicking on create a new Visual state group, similarly XAML could have been manually editing the XAML.

VisualStateGroup

In Blend 3.0/Silverlight 3.0 you can still create visual states the old way for UserControls but for custom controls this option becomes disabled/unavailable.

CCVisualStateGroup

One reason I could think for this is that all Visual States for a custom control need not be defined in XAML, since most of the time a custom control is build to just show/handle different states but manipulating visual states is part of templating a control for anything other than its default behavior, the most important part as far as Visual States of a Custom Controls is the ability for the control to make a transition from one state to another state, which more than likely happens from the code behind.

It is more important for a Custom Control code behind to know the different states the control and be in than for the XAML which just fires the visual state. In Silverlight 2.0/Blend 2.0 SP1 mapping the visual states created in XAML in code behind by defining Attributes was optional but in Silverlight 3.0 /Blend 3.0 it is the only way to create custom states for a custom control.

By attaching TemplateVisualState Attribute to the Custom Control the visual states can be defined at one place and can be easily manipulated, below is an example of it.

[TemplateVisualState(GroupName = "FocusGroup", Name = "Focus")]
[TemplateVisualState(GroupName = "FocusGroup", Name = "UnFocus")]
[TemplateVisualState(GroupName = "SelectedGroup", Name = "Selected")]
[TemplateVisualState(GroupName = "SelectedGroup", Name = "UnSelected")]
public class SomeCustomControl : Control
{
    public SomeCustomControl()
    {
        this.DefaultStyleKey = typeof(SomeCustomControl);
    }
}

Blend automatically identifies them and allows users to do visual changes to visual states.

 CCVSs

Defining custom visual states this way give developers more power to make the transition between states and since designers don’t have the option of  creating new custom states there will be little confusion between developers/designers.

Posted on Sunday, August 2, 2009 4:13 AM Silverlight | Back to top


Comments on this post: Defining Custom VSM states for Custom Controls in Silverlight 3 / Blend 3

# re: Defining Custom VSM states for Custom Controls in Silverlight 3 / Blend 3
Requesting Gravatar...
the link to Download the Sample doesn't work.
Left by Brian on Sep 19, 2009 1:23 AM

# re: Defining Custom VSM states for Custom Controls in Silverlight 3 / Blend 3
Requesting Gravatar...
the download link not working , it redirect to some junk page.
Left by Bill on Mar 09, 2010 9:36 AM

# re: Defining Custom VSM states for Custom Controls in Silverlight 3 / Blend 3
Requesting Gravatar...
Hi there, I found your blog via Google while searching and your post looks very interesting for me
Left by toplum on Jul 28, 2010 11:51 PM

Your comment:
 (will show your gravatar)


Copyright © Imran Shaik | Powered by: GeeksWithBlogs.net