c# - Enumerate and apply WPF styles programmatically -


i have wpf button such

<button name="helloworldbutton"         width="100"         height="100"         horizontalalignment="center"         verticalalignment="center"         style="{staticresource tilebutton}">     hello world </button> 

using wpf styling have applied style template shown below

<style x:key="tilebutton" targettype="button">     <setter property="template">         <setter.value>             <controltemplate targettype="button">                 <border x:name="focusrect"                         margin="-6"                         borderthickness="6">                     <contentpresenter />                     <border.borderbrush>                         <solidcolorbrush x:name="focusrectbrush" color="transparent" />                     </border.borderbrush>                     <visualstatemanager.visualstategroups>                         <visualstategroup x:name="commonstates">                             <visualstate x:name="normal" />                             <visualstate x:name="mouseover">                                 <storyboard>                                     <coloranimation duration="0"                                                     storyboard.targetname="focusrectbrush"                                                     storyboard.targetproperty="color"                                                     to="red" />                                 </storyboard>                             </visualstate>                             <visualstate x:name="pressed">                                 <storyboard>                                     <coloranimation duration="0"                                                     storyboard.targetname="focusrectbrush"                                                     storyboard.targetproperty="color"                                                     to="white" />                                 </storyboard>                             </visualstate>                         </visualstategroup>                     </visualstatemanager.visualstategroups>                 </border>             </controltemplate>         </setter.value>     </setter> </style> 

i apply mouseover visualstate programmatically. have looked through helloworldbutton.style property , cannot see obvious way of achieving this.

note: understand trivial programmatically add border button directly without using declared xaml style sheet, in scenario not viable approach.

finally worked out.

the code looking simple

visualstatemanager.gotostate(helloworldbutton, "mouseover", true); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -