wpf - Change TextBox Foreground on focus in VisualState -



wpf - Change TextBox Foreground on focus in VisualState -

i want alter foreground of textbox in silverlight3 using visualstate in resources. code below have tried far. didn't work. please guide me.

<textbox x:name="emailtextbox" text="{binding username, mode=twoway}" grid.row="0" grid.column="1" style="{staticresource textboxemailstyle}"/>

and here referenced style textbox above:

<style x:key="textboxemailstyle" targettype="textbox"> <setter property="template"> <setter.value> <controltemplate targettype="textbox"> <grid x:name="rootelement"> <visualstatemanager.visualstategroups> <visualstategroup x:name="focusstates"> <visualstategroup.transitions> <visualtransition generatedduration="0:0:0.3"/> </visualstategroup.transitions> <visualstate x:name="focused"> <storyboard> <coloranimation duration="0" to="#00000000" storyboard.targetname="contentelement" storyboard.targetproperty="(contentelement.foreground). (solidcolorbrush.color)"/> </storyboard> </visualstate> </visualstategroup> </visualstatemanager.visualstategroups> <border x:name="border" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}" opacity="1"> <grid> <border x:name="readonlyvisualelement" background="#5ec9c9c9" opacity="0"/> <border x:name="mouseoverborder" borderbrush="transparent" borderthickness="1"> <stackpanel orientation="horizontal"> <image width="40" source="/images/sign_in_email.png" margin="5,5,5,5"/> <scrollviewer x:name="contentelement" borderthickness="0" istabstop="false" padding="{templatebinding padding}" verticalalignment="center" margin="4"/> </stackpanel> </border> </grid> </border> </grid> </controltemplate> </setter.value> </setter> </style>

your storyboard.targetproperty not correct, , need provide default state "unfocused" without foreground alter (or can never go "normal").

<visualstate x:name="unfocused"/> <visualstate x:name="focused"> <storyboard> <coloranimation duration="0" to="#00000000" storyboard.targetname="contentelement" storyboard.targetproperty="(control.foreground).(solidcolorbrush.color)"/> </storyboard> </visualstate>

and btw: color #00000000 not visible, maybe want alter #ff000000

and create sure foreground set solidcolorbrush instance default:

<scrollviewer x:name="contentelement" foreground="white" ... />

usually when 1 wants alter template of command include visualstates defined control. seek add together states, maybe visualstate update method exits because the other textbox states not defined.

<visualstatemanager.visualstategroups> <visualstategroup x:name="focusstates"> <visualstate x:name="focused">...</visualstate> <visualstate x:name="unfocused"/> </visualstategroup> <visualstategroup x:name="commonstates"> <visualstate x:name="normal"/> <visualstate x:name="mouseover"/> <visualstate x:name="disabled"/> <visualstate x:name="readonly"/> </visualstategroup> <visualstategroup x:name="validationstates"> <visualstate x:name="valid"/> <visualstate x:name="invalidfocused"/> <visualstate x:name="invalidunfocused"/> </visualstategroup> </visualstatemanager.visualstategroups>

edit: ok, working in sl4 not in sl3? well, have @ features added sl4 , see if find explains why template doesn't work in sl3 correctly sl4.

wpf xaml silverlight windows-phone-7

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -