visual studio - How to change foreground color of button in WPF? -


i want change text color (foreground) of button when mouse over. have changed background color editing following code

<style x:key="buttonstyle_black" targettype="{x:type button}">         <setter property="foreground" value="{dynamicresource textbrush}"/>         <setter property="background" value="{dynamicresource graybrush10}"/>         <setter property="borderbrush" value="{dynamicresource textboxborderbrush}"/>         <setter property="borderthickness" value="1"/>         <setter property="controls:controlshelper.contentcharactercasing" value="upper"/>         <setter property="controls:controlshelper.cornerradius" value="3"/>         <setter property="fontfamily" value="{dynamicresource defaultfont}"/>         <setter property="fontsize" value="{dynamicresource uppercasecontentfontsize}"/>         <setter property="fontweight" value="bold"/>         <setter property="minheight" value="25"/>         <setter property="padding" value="5,6"/>         <setter property="template">             <setter.value>                 <controltemplate targettype="{x:type button}">                     <grid>                         <border x:name="background" background="{templatebinding background}" cornerradius="{binding (controls:controlshelper.cornerradius), mode=oneway, relativesource={relativesource templatedparent}}"/>                         <border x:name="border" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{x:null}" cornerradius="{binding (controls:controlshelper.cornerradius), mode=oneway, relativesource={relativesource templatedparent}}" snapstodevicepixels="{templatebinding snapstodevicepixels}"/>                         <border x:name="disabledvisualelement" background="{dynamicresource controlsdisabledbrush}" cornerradius="{binding (controls:controlshelper.cornerradius), mode=oneway, relativesource={relativesource templatedparent}}" ishittestvisible="false" opacity="0" snapstodevicepixels="{templatebinding snapstodevicepixels}"/>                         <controls:contentcontrolex x:name="part_contentpresenter" contentcharactercasing="{binding (controls:controlshelper.contentcharactercasing), relativesource={relativesource templatedparent}}" contenttemplate="{templatebinding contenttemplate}" content="{templatebinding content}" contentstringformat="{templatebinding contentstringformat}" horizontalcontentalignment="{templatebinding horizontalcontentalignment}" padding="{templatebinding padding}" recognizesaccesskey="true" snapstodevicepixels="{templatebinding snapstodevicepixels}" verticalcontentalignment="{templatebinding verticalcontentalignment}"/>                     </grid>                     <controltemplate.triggers>                         <trigger property="ismouseover" value="true">                             <setter property="foreground" value="black"/>                         </trigger>                         <trigger property="ispressed" value="true">                         </trigger>                         <trigger property="iskeyboardfocuswithin" value="true">                             <setter property="borderbrush" targetname="border" value="{dynamicresource buttonmouseoverborderbrush}"/>                             <setter property="borderthickness" targetname="border" value="2"/>                         </trigger>                         <trigger property="isenabled" value="false">                             <setter property="opacity" targetname="disabledvisualelement" value="0.7"/>                             <setter property="opacity" targetname="part_contentpresenter" value="0.3"/>                         </trigger>                     </controltemplate.triggers>                 </controltemplate>             </setter.value>         </setter>     </style> 

but editing template foreground color change not working.

you can using style,

   <window.resources>         <style x:key="buttoncancel" targettype="{x:type button}">             <setter property="foreground">                 <setter.value>                     <lineargradientbrush endpoint="0.5,1" startpoint="0.5,0">                         <gradientstop color="red" offset="0"/>                                           </lineargradientbrush>                 </setter.value>             </setter>             <style.triggers>                 <trigger property ="ismouseover" value="true">                     <setter property= "foreground"  >                         <setter.value>                             <lineargradientbrush endpoint="0.5,1" startpoint="0.5,0">                                 <gradientstop color="green" offset="0"/>                             </lineargradientbrush>                         </setter.value>                     </setter>                 </trigger>             </style.triggers>         </style>     </window.resources>     <grid>         <button style="{dynamicresource buttoncancel}"   fontsize="18" fontweight="bold" width="144" name="btncancel"                 horizontalalignment="right" grid.row="1"  grid.column="1" margin="0,73.5,0,55.5"> test         </button>     </grid> 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -