WPF TabItem OnMouseOver shall trigger the visibility of a Button inside the TabItem -
i have tabcontrol containing tabitems. overwrote itemtemplate contain:
a textblock showing caption of tabitem a button (x) closes tabnow create "x"-button visible, when tabitem either selected or mouse on it.
this xaml code far...
<tabcontrol x:name="tabcontrol" itemssource="{binding openeditems}"> <tabcontrol.itemtemplate> <datatemplate> <grid name="grid" verticalalignment="center"> <grid.columndefinitions> <columndefinition width="*" /> <columndefinition width="auto" /> </grid.columndefinitions> <textblock text="{binding tabcaption}" grid.column="0" foreground="white" horizontalalignment="left" margin="3" name="label_tabtitle" verticalalignment="center" /> <button content="x" grid.column="1" foreground="white" horizontalalignment="right" margin="3" name="button_close" verticalalignment="center" width="20" style="{staticresource {x:static toolbar.buttonstylekey}}" visibility="hidden" click="button_close_click_1"> </button> </grid> <datatemplate.triggers> <trigger property="ismouseover" value="true" > <setter targetname="button_close" property="visibility" value="visible"/> </trigger> </datatemplate.triggers> </datatemplate> </tabcontrol.itemtemplate> <tabcontrol.itemcontainerstyle> <style targettype="tabitem"> <setter property="background" value="#1c1c1c" /> <setter property="content" value="{binding tabcontentview}"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type tabitem}"> <grid name="grid" background="{staticresource graybrush}"> <contentpresenter x:name="contentsite" verticalalignment="center" horizontalalignment="center" contentsource="header" recognizesaccesskey="true"> </contentpresenter> </grid> <controltemplate.triggers> <trigger property="isselected" value="true"> <setter targetname="grid" property="background" value="{staticresource bluebrush}" /> </trigger> <trigger property="ismouseover" value="true"> <setter targetname="grid" property="background" value="{staticresource lightbluebrush}" /> </trigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> </style> </tabcontrol.itemcontainerstyle> </tabcontrol>
with trigger within datatemplate kind of works.. but: have hover mouse straight on label in order show button. basically, impossible click button, because disappears again.
i appreciate help these wpf templates!
thanks, christian
it looks though tabitem not have background set not catching mouseoverevent
. since textblock has foreground set , has text, captures mouseoverevent. seek setting background
kid grid of datatemplate
transparent
, should see mouseoverevent
caught , show close button.
<tabcontrol x:name="tabcontrol" itemssource="{binding openeditems}"> <tabcontrol.itemtemplate> <datatemplate> <grid name="grid" verticalalignment="center" background="transparent"> ... </grid> ... </datatemplate> </tabcontrol.itemtemplate> ... </tabcontrol>
wpf triggers datatemplate
No comments:
Post a Comment