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 textblock
s 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
Post a Comment