c# - VisualStateManager not working when value is passed through a converter for applying a Button Bg -


i applying button's background color through converter. @ first applied after hovered or pressed background color gone forever , not come back.

desired behavior

default state

noraml

hovered

enter image description here

after hover state

noraml

my problem

the orange background not appear again when hovered state over

implementation

button usage

<button content="continue" style="{staticresource buttonanycolorstyle}">     <button.background>         <solidcolorbrush color="{binding something, converter={staticresource panelbgcolorconverter}, mode=twoway}"  />     </button.background> </button> 

button style

<style x:key="buttonanycolorstyle" targettype="button">     <setter property="borderbrush" value="{staticresource phoneforegroundbrush}" />     <setter property="template">         <setter.value>             <controltemplate targettype="button">                 <grid background="transparent">                     <visualstatemanager.visualstategroups>                         <visualstategroup x:name="commonstates">                             <visualstate x:name="normal">                             </visualstate>                             <visualstate x:name="mouseover">                                 <storyboard>                                     <objectanimationusingkeyframes storyboard.targetproperty="foreground"                                                                    storyboard.targetname="contentcontainer">                                         <discreteobjectkeyframe keytime="0"                                                                 value="{binding path=background, elementname=buttonbackground}" />                                     </objectanimationusingkeyframes>                                     <objectanimationusingkeyframes storyboard.targetproperty="background"                                                                    storyboard.targetname="buttonbackground">                                         <discreteobjectkeyframe keytime="0"                                                                 value="{binding path=foreground, elementname=contentcontainer}" />                                     </objectanimationusingkeyframes>                                     <objectanimationusingkeyframes storyboard.targetproperty="borderbrush"                                                                    storyboard.targetname="buttonbackground">                                         <discreteobjectkeyframe keytime="0"                                                                 value="{binding path=background, elementname=buttonbackground}" />                                     </objectanimationusingkeyframes>                                 </storyboard>                             </visualstate>                             <visualstate x:name="pressed">                                 <storyboard>                                     <objectanimationusingkeyframes storyboard.targetproperty="foreground"                                                                    storyboard.targetname="contentcontainer">                                         <discreteobjectkeyframe keytime="0"                                                                 value="{binding path=background, elementname=buttonbackground}" />                                     </objectanimationusingkeyframes>                                     <objectanimationusingkeyframes storyboard.targetproperty="background"                                                                    storyboard.targetname="buttonbackground">                                         <discreteobjectkeyframe keytime="0"                                                                 value="{binding path=foreground, elementname=contentcontainer}" />                                     </objectanimationusingkeyframes>                                     <objectanimationusingkeyframes storyboard.targetproperty="borderbrush"                                                                    storyboard.targetname="buttonbackground">                                         <discreteobjectkeyframe keytime="0"                                                                 value="{binding path=background, elementname=buttonbackground}" />                                     </objectanimationusingkeyframes>                                 </storyboard>                             </visualstate>                             <visualstate x:name="disabled">                                 <storyboard>                                     <doubleanimationusingkeyframes storyboard.targetproperty="(uielement.opacity)"                                                                    storyboard.targetname="buttonbackground">                                         <easingdoublekeyframe keytime="0"                                                               value="0.2" />                                     </doubleanimationusingkeyframes>                                 </storyboard>                             </visualstate>                         </visualstategroup>                     </visualstatemanager.visualstategroups>                     <border x:name="buttonbackground"                             background="{templatebinding background}"                             cornerradius="12"                             borderthickness="1"                             margin="{staticresource phonetouchtargetoverhang}">                         <contentcontrol x:name="contentcontainer"                                         contenttemplate="{templatebinding contenttemplate}"                                         content="{templatebinding content}"                                         foreground="{templatebinding foreground}"                                         horizontalcontentalignment="{templatebinding horizontalcontentalignment}"                                         padding="{templatebinding padding}"                                         verticalcontentalignment="{templatebinding verticalcontentalignment}" />                     </border>                 </grid>             </controltemplate>         </setter.value>     </setter> </style> 

converter

 public class panelbgcolorconverter : ivalueconverter  {     public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         if (value something)         {             switch ((something)value)             {                 case something.apptheme:                     return application.current.resources["appthemecoloronly"];                  case something.phone:                     return application.current.resources["appgreencoloronly"];                  case something.email:                     return application.current.resources["appyellowcoloronly"];                  default:                     return colors.transparent;             }         }         else return colors.transparent;     }      public object convertback(object value, type targettype, object parameter, cultureinfo culture)     {         throw new notimplementedexception();     } } 

please note if color passed staticresource via xaml, behavior perfect. problem lies converted value


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -