开发者

Automatically Change VisualState in Silverlight

If you create a simple button and then choose Edi开发者_如何学JAVAt Template -> Edit a Copy, Blend will automatically generate a style area, along with all the button states (MouseEnter, MouseLeave, Pressed, etc). Nowhere in the generated code does it say that on a "MouseOver" event, change the state to "MouseOver", but it still manages to work!

How does a standard button do it? Is there some sort of AutoEventWireUp going on?


Controls themselves define the states they respect. Unfortunately, there's no magic auto-wiring going on. The Button contains code that determines when the mouse is over it and, in that case, to set it's visual state to MouseOver. The TemplateVisualStateAttribute is what lets Blend know that there is a valid state of a certain on this control, but the code in the control itself is what actually determines what state it is in.

If you are developing your own control, this puts the burden of defining which states your control supports on you, as well as the job of correctly determining which state you are in.

FYI: Most of the built in controls have a list of their supported states in the MSDN documentation. For example, Button for Silverlight 3 is here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜