is there anyway animate textbox.foregroundproperty
?
<color x:key="normalcolor">#ff666666</color> <solidcolorbrush x:key="normalbrush" color="{staticresource normalcolor}" /> <color x:key="mouseovercolor">#ff666666</color> <solidcolorbrush x:key="mouseoverbrush" color="{staticresource mouseovercolor}" /> <controltemplate x:key="regulartextboxtemplate" targettype="{x:type textbox}"> <grid> <visualstatemanager.visualstategroups> <visualstategroup x:name="commonstates"> <visualstategroup.transitions> <visualtransition generatedduration="0:0:0.1"/> </visualstategroup.transitions> <visualstate x:name="normal"/> <visualstate x:name="mouseover"> <storyboard> <!-- storyboard animating foreground here... --> </storyboard> </visualstate> </visualstategroup > </visualstatemanager> <scrollviewer x:name="part_contenthost" borderthickness="0" istabstop="false" background="{x:null}"/> </grid> </controltemplate> <style x:key="regulartextbox" targettype="{x:type textbox}"> <setter property="foreground" value="{staticresource normalbrush}"/> <setter property="template" value="{staticresource regulartextboxtemplate}"/> </style>
my tried storyboards are:
<coloranimationusingkeyframes storyboard.targetname="part_contenthost" storyboard.targetproperty="(foreground).(solidcolorbrush.color)"> <easingcolorkeyframe keytime="0" value="{staticresource mouseovercolor}" /> </coloranimationusingkeyframes> <coloranimationusingkeyframes storyboard.targetname="part_contenthost" storyboard.targetproperty="(control.foreground).(solidcolorbrush.color)"> <easingcolorkeyframe keytime="0" value="{staticresource mouseovercolor}" /> </coloranimationusingkeyframes> <coloranimationusingkeyframes storyboard.targetname="part_contenthost" storyboard.targetproperty="(textelement.foreground).(solidcolorbrush.color)"> <easingcolorkeyframe keytime="0" value="{staticresource mouseovercolor}" /> </coloranimationusingkeyframes> <coloranimationusingkeyframes storyboard.targetproperty="(foreground).(solidcolorbrush.color)"> <easingcolorkeyframe keytime="0" value="{staticresource mouseovercolor}" /> </coloranimationusingkeyframes> <coloranimationusingkeyframes storyboard.targetproperty="(textbox.foreground).(solidcolorbrush.color)"> <easingcolorkeyframe keytime="0" value="{staticresource mouseovercolor}" /> </coloranimationusingkeyframes> <coloranimationusingkeyframes storyboard.targetproperty="(control.foreground).(solidcolorbrush.color)"> <easingcolorkeyframe keytime="0" value="{staticresource mouseovercolor}" /> </coloranimationusingkeyframes> <coloranimationusingkeyframes storyboard.targetproperty="(textelement.foreground).(solidcolorbrush.color)"> <easingcolorkeyframe keytime="0" value="{staticresource mouseovercolor}" /> </coloranimationusingkeyframes>
none of them work. idea? possible?
this more problematic thought. here original answer:
it's possible - that's coloranimationxxx classes for.
your code similar code example here, animates colour coloranimation instead. property in example takes brush (just textbox.foreground) defined in xaml , given name can referenced animation.
so in case pertinent code be:
<visualstate name="..."> <storyboard> <coloranimation to="green" storyboard.targetname="tbbrush" storyboard.targetproperty="color"/> </storyboard> </visualstate>
and:
<textbox.foreground> <solidcolorbrush x:name="tbbrush" color="#ff666666"/> </textbox.foreground>
that well, in theory, until realised didn't work in style. whereas background
property of grid within style animatable, like:
storyboard.targetproperty="(grid.background).(solidcolorbrush.color)"
it more difficult find property animate have effect on foreground of text. tried textelement.foreground
, seems intuitive, , able set property @ grid , scrollviewer levels expected have effect on child objects underneath - including whatever object @ bottom level contains text of textbox. assumption textbox content internally set textblock, obey value of foreground attached property set on it. seems assumption incorrect, , content of part_contenthost scrollviewer set control logic within textbox lower level object not obey of foreground dependency properties in object tree between top level textbox , itself.
the problem how set foreground property of textbox within style of textbox being styled. testing, tried set twoway templatedparent binding. think got propertypath color of solidcolorbrush right, still didn't work color property apparently immutable @ point. believe issue documented here.
on top of fact doesn't work, setting foreground property internally did not seem right external consumers expect in control of value of property. so, given foreground of textbox not obey in style, came conclusion functionality best implemented nested textbox within textbox style. outer style contains state manager , of layout, inner textbox has own style , control template designed display text bit. outer style able set foreground property of inner textbox, inner 1 obey, , crucially outer 1 can set value in state manager.
<controltemplate x:key="regulartextboxtemplate" targettype="{x:type textbox}"> <grid> <visualstatemanager.visualstategroups> <visualstategroup x:name="commonstates"> <visualstategroup.transitions> <visualtransition generatedduration="0:0:0.1"/> </visualstategroup.transitions> <visualstate x:name="normal"/> <visualstate x:name="mouseover"> <storyboard> <coloranimation to="hotpink" storyboard.targetname="internaltextbox" storyboard.targetproperty="(textbox.foreground).(solidcolorbrush.color)"/> </storyboard> </visualstate> </visualstategroup> </visualstatemanager.visualstategroups> <textbox foreground="black" text="{templatebinding text}" x:name="internaltextbox"> <textbox.style> <style targettype="{x:type textbox}"> <setter property="template"> <setter.value> <controltemplate targettype="{x:type textbox}"> <grid background="{x:null}"> <scrollviewer x:name="part_contenthost" borderthickness="0" istabstop="false" background="{x:null}" /> </grid> </controltemplate> </setter.value> </setter> </style> </textbox.style> </textbox> </grid> </controltemplate> <style x:key="regulartextbox" targettype="{x:type textbox}"> <setter property="template" value="{staticresource regulartextboxtemplate}"/> </style>
i interested in hearing other people's comments on approach, , whether there problems have not considered. based on attempts @ solving problem , snooping resultant application, simplest solution can see @ moment.