wpf - Change TabItem's Header FontWeight -


i change tabitem's header fontweight bold when isselected = true resourcedictionary.

some code

 <setter property="template">         <setter.value>             <controltemplate targettype="{x:type tabitem}">                 <grid>                     <border name="border"                             background="white"                             borderbrush="white"                              borderthickness="1,1,1,0"                             margin="0,0,0,-1" >                         <contentpresenter x:name="contentsite"                                           height="25"                                           verticalalignment="bottom"                                           horizontalalignment="center"                                           contentsource="header"                                           margin="12,2,12,2"/>                     </border>                 </grid>                 <controltemplate.triggers>                     <trigger property="isselected" value="true">                         <setter targetname="border" property="background" value="#f2f1f0" />                         <setter targetname="border" property="borderbrush" value="gray" />                         <setter targetname="border" property="borderthickness" value="0.5,0.7,0.5,0" />                         <setter property="header">                             <setter.value>                                 <textblock text="{binding path=header.title, relativesource={relativesource findancestor, ancestortype={x:type tabitem}}}"                                            fontweight="bold" />                             </setter.value>                         </setter>                     </trigger>                     <trigger property="isselected" value="false">                         <setter targetname="border" property="background" value="white" />                         <setter targetname="border" property="borderbrush" value="gray" />                         <setter targetname="border" property="borderthickness" value="0,0,0,0.5" />                     </trigger>  .....etc..... 

the above approach doesn't work. setting headertemplate instead of header works ruins template. finally, setting textblock.fontweight property inside trigger changes textblocks inside tabitem.

any proposals?

update

i picked @shineking answer because helped me solve problem. did add datatrigger textblock used header "custom" tabitem.

            <textblock.style>             <style targettype="textblock">                 <style.triggers>                     <datatrigger binding="{binding path=isselected, relativesource={relativesource findancestor, ancestortype={x:type tabitem}}}" value="true">                         <setter property="fontweight" value="bold"/>                     </datatrigger>                 </style.triggers>             </style>         </textblock.style> 

could try code change textblock bold

<tabcontrol>    <tabcontrol.resources>       <style targettype="textblock" x:key="headertextblockstyle">          <style.triggers>             <datatrigger binding="{binding isselected,                           relativesource={relativesource ancestortype=tabitem}}"                          value="true">                 <setter property="fontweight" value="bold"/>              </datatrigger>           </style.triggers>        </style>     </tabcontrol.resources>     <tabitem>        <tabitem.header>           <textblock text="header text"                      style="{staticresource headertextblockstyle}"/>        </tabitem.header>     </tabitem> </tabcontrol> 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -