Overview
The control templates in WPF and Silverlight support the perception of the custom control, the appearance, the visual effect of the accusation, and the sense of responsiveness of the control interaction, such as the change in state of pressing the mouse on the control, the control gaining focus, and so on. Microsoft introduced a new concept visual state Manager in Silverlight 2 Beta 2, providing a great convenience for us to create interactive control templates. Next I'll use a few articles to introduce the visual state management in Silverlight 2.
This article is the second installment of the series that describes how to customize the perception of a control with visual state management in Silverlight 2. In the previous article we introduced some of the basic concepts of visual state management, and here is an example of how to customize the perception of a control using visual state management, and finally the example effect we finished is as shown in the following illustration:
The examples in this article use the code in this article.
Defining a control template
We'll now define the template for the CheckBox control, the part described in the previous article, as shown in the following code:
<controltemplate targettype= "CheckBox"
<stackpanel x:name= "Root"
<!--Outerborder
<border width= "height="
<!--innerborder
<border x:name= "in Nerborder
<grid>
<!--higlight-->
<border x:name= Highlightbor Der > </border>
<!--Glow
<rectangle x:name= "Glow" opacity= "0" ></ Rectangle>
<!-checkmark graphic-->
<path x:name= "checkmark" opacity= "0" >< /path>
<!--indeterminate rect-->
<rectangle x:name= "Indeterminaterect" opacity= " 0 "></rectangle>
</grid>
</border>
</border>
<!--Cont Entpresenter
<contentpresenter/>
</stackpanel>
</controltemplate>
To reduce the code, some attributes are removed, but some of the necessary part names are given. Now that we're running, we can see that although the checkbox has a style, it doesn't have any interaction effects, such as clicking the mouse and the checkbox is not selected.