开发者

How do you give style to the active state of a TextBox?

I know I can rewrite the Template of my TextBoxes to redefine it's visual states but isn't there an easy way to just say: "make this textbox yellow when it is active (got focus)"?

Something like "input:active" in css.

Maybe a way in silverlight to set the style to a visual state of开发者_StackOverflow a control instead of it's general look?

Thanks


You should make a Style which changes the VisualState.

See here: http://msdn.microsoft.com/en-us/library/ms752068.aspx


If you dont want to use VisualStates you can simply set a FocusVisualStyle directly on the TextBox.

<TextBox FocusVisualStyle={...} ... />

Or you can use a trigger in the normal style. In fact the documentation above suggests using a trigger can be a better approach:

If you are intending control-specific behavior that is deliberately not coherent across a theme, a much better approach is to use triggers in styles for individual input state properties, such as IsFocused or IsKeyboardFocusWithin,

A trigger is the closest thing to the css pseudo-class approach, unfortunately its not as succinct.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜