wpf - Binding TextBlock color to Button IsEnabled from Style -


i trying define style used button holds textblock content , when button has isenabled=false want set textblock's foregroung color.

<button style="{staticresource transparentbuttonstyle}"          isenabled="{binding isallowed}">       <textblock text="click me"                   style="{staticresource hyperlinkstyle}">       </textblock> </button>  <style x:key="transparentbuttonstyle" targettype="{x:type button}">      <setter property="template">          <setter.value>              <controltemplate targettype="button">                  <border background="transparent">                      <contentpresenter/>                  </border>              </controltemplate>          </setter.value>      </setter> </style>  <style x:key="hyperlinkstyle" targettype="textblock">       <setter property="foreground" value="blue"  />      <style.triggers>          <trigger property="ismouseover" value="true">              <setter property="cursor" value="hand" />              <setter property="foreground" value="lightblue" />              <setter property="textdecorations" value="underline" />          </trigger>      </style.triggers> </style> 

can modify textblock's style grab parent button's isenabled value somehow able set foreground color ?

you can add <trigger property="isenabled" value="false"> hyperlinkstyle, recommend create linkbuttonstyle instead, final markup fill cleaner:

  <button content="link text"  style="{staticresource linkbuttonstyle}" /> 

this makes views cleaner...

here's linkbutton template:

<style x:key="linkbuttonstyle" targettype="button">     <setter property="foreground" value="{staticresource linkbuttontext}" />     <setter property="background" value="transparent" />     <setter property="template">         <setter.value>             <controltemplate targettype="button">                 <textblock x:name="contentpresenter" background="{templatebinding background}"                            text="{templatebinding content}" foreground="{templatebinding foreground}"                            horizontalalignment="{templatebinding horizontalcontentalignment}"                             verticalalignment="{templatebinding verticalcontentalignment}"/>                  <controltemplate.triggers>                     <trigger property="isenabled" value="false">                         <setter targetname="contentpresenter" property="foreground" value="{dynamicresource linkbuttondisabled}" />                     </trigger>                     <multitrigger>                         <multitrigger.conditions>                             <condition property="ismouseover" value="true" />                             <condition property="isenabled" value="true" />                         </multitrigger.conditions>                         <setter targetname="contentpresenter" property="textdecorations" value="underline"/>                     </multitrigger>                 </controltemplate.triggers>             </controltemplate>         </setter.value>     </setter> </style> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -