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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -