xaml - VisualStateManager Focus state remains after focus -
i have winrt app control template textbox. want background go gray when control in focus. code below this, when control loses focus gray background remains. how make background returns normal when control loses focus?
<controltemplate x:key="greyfocustextbox" targettype="textbox"> <grid> <visualstatemanager.visualstategroups> <visualstategroup x:name="commonstates"> <visualstate x:name="normal" /> <visualstate x:name="pointerover" /> <visualstate x:name="pressed" /> <visualstate x:name="disabled" /> </visualstategroup> <visualstategroup x:name="focusedstates"> <visualstate x:name="focused"> <storyboard> <doubleanimation duration="0" to="1" storyboard.targetproperty="opacity" storyboard.targetname="backgroundelement" /> </storyboard> </visualstate> <visualstate x:name="unfocused" /> <visualstate x:name="pointerfocused" /> </visualstategroup> </visualstatemanager.visualstategroups> <border x:name="backgroundelement" background="gray" grid.columnspan="2" margin="{templatebinding borderthickness}" opacity="0" /> <border x:name="borderelement" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" grid.columnspan="2"/> <scrollviewer x:name="contentelement" horizontalscrollmode="{templatebinding scrollviewer.horizontalscrollmode}" horizontalscrollbarvisibility="{templatebinding scrollviewer.horizontalscrollbarvisibility}" istabstop="false" ishorizontalrailenabled="{templatebinding scrollviewer.ishorizontalrailenabled}" isverticalrailenabled="{templatebinding scrollviewer.isverticalrailenabled}" isdeferredscrollingenabled="{templatebinding scrollviewer.isdeferredscrollingenabled}" margin="{templatebinding borderthickness}" padding="{templatebinding padding}" verticalscrollbarvisibility="{templatebinding scrollviewer.verticalscrollbarvisibility}" verticalscrollmode="{templatebinding scrollviewer.verticalscrollmode}" zoommode="disabled"/> </grid> </controltemplate>
it seems textbox doesn't go unfocused state rename unfocused
normal
& removed storyboard
, worked. below code worked me.
<controltemplate x:key="greyfocustextbox" targettype="textbox"> <grid> <visualstatemanager.visualstategroups> <visualstategroup x:name="focusedstates"> <visualstate x:name="focused"> <storyboard> <doubleanimation duration="0" to="1" storyboard.targetproperty="opacity" storyboard.targetname="backgroundelement" /> </storyboard> </visualstate> <visualstate x:name="normal"/> <visualstate x:name="pointerfocused" /> </visualstategroup> </visualstatemanager.visualstategroups> <border x:name="backgroundelement" background="gray" grid.columnspan="2" margin="{templatebinding borderthickness}" opacity="0" /> <border x:name="borderelement" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" grid.columnspan="2"/> <scrollviewer x:name="contentelement" horizontalscrollmode="{templatebinding scrollviewer.horizontalscrollmode}" horizontalscrollbarvisibility="{templatebinding scrollviewer.horizontalscrollbarvisibility}" istabstop="false" ishorizontalrailenabled="{templatebinding scrollviewer.ishorizontalrailenabled}" isverticalrailenabled="{templatebinding scrollviewer.isverticalrailenabled}" isdeferredscrollingenabled="{templatebinding scrollviewer.isdeferredscrollingenabled}" margin="{templatebinding borderthickness}" padding="{templatebinding padding}" verticalscrollbarvisibility="{templatebinding scrollviewer.verticalscrollbarvisibility}" verticalscrollmode="{templatebinding scrollviewer.verticalscrollmode}" zoommode="disabled"/> </grid> </controltemplate>
Comments
Post a Comment