WPF Button Style Background Image Swap on IsEnabled -
we use custom image buttons in our project. apply via style have need 'disable' buttons , trying swap out image new one.
the first trigger works 100% expected. when button's isenabled == true, button 'green'. when button's isenabled == false, green removed , foreground color changes grey image not load up.
am missing something???
<style targettype="{x:type button}" x:key="greengreybutton"> <style.triggers> <trigger property="isenabled" value="true"> <setter property="background"> <setter.value> <imagebrush imagesource="..\images\ui\buttons\green.png"/> </setter.value> </setter> <setter property="foreground" value="#ffa30046"/> </trigger> <trigger property="isenabled" value="false"> <setter property="background"> <setter.value> <imagebrush imagesource="..\images\ui\buttons\grey.png"/> </setter.value> </setter> <setter property="foreground" value="gray"/> </trigger> </style.triggers> </style>
it's pity when isenabled
false, native style override settings (with default gray background). can re-template button this:
<style targettype="{x:type button}" x:key="greengreybutton"> <setter property="template"> <setter.value> <controltemplate targettype="button"> <border background="{templatebinding background}"> <contentpresenter content="{templatebinding content}" margin="{tempatebinding padding}" verticalalignment="{templatebinding verticalcontentalignment}" horizontalalignment="{templatebinding horizontalcontentalignment}"/> </border> </controltemplate> </setter.value> </setter> <setter property="background"> <setter.value> <imagebrush imagesource="..\images\ui\buttons\green.png"/> </setter.value> </setter> <setter property="foreground" value="#ffa30046"/> <style.triggers> <trigger property="isenabled" value="false"> <setter property="background"> <setter.value> <imagebrush imagesource="..\images\ui\buttons\grey.png"/> </setter.value> </setter> <setter property="foreground" value="gray"/> </trigger> </style.triggers> </style>
Comments
Post a Comment