c# - IsMouseOver trigger not working for GridViewColumn WPF XAML -
here code of xaml:
<page.resources> <style x:key="cells" targettype="gridviewcolumnheader"> <style.triggers> <trigger property="isenabled" value="true"> <setter property="background" value="#ff00b9ff"></setter> <setter property="foreground" value="white"></setter> <setter property="borderbrush" value="#ff00b9ff"></setter> <setter property="padding" value="8"></setter> <setter property="minwidth" value="100"></setter> </trigger> <trigger property="ismouseover" value="true"> <setter property="background" value="#ff00b9ff"></setter> <setter property="foreground" value="white"></setter> <setter property="borderbrush" value="#ff00b9ff"></setter> <setter property="padding" value="2"></setter> <setter property="minwidth" value="100"></setter> </trigger> </style.triggers> </style> </page.resources> <grid> <label content="notifications" verticalalignment="top" horizontalalignment="left" fontsize="20"></label> <listview background="{x:null}" fontsize="17" margin="0,30,0,0" itemssource="{binding notifications}" horizontalalignment="center" borderbrush="{x:null}"> <listview.view> <gridview allowscolumnreorder="false"> <gridviewcolumn header="sl no." displaymemberbinding="{binding slno}" headercontainerstyle="{staticresource cells}"></gridviewcolumn> <gridviewcolumn header="message" displaymemberbinding="{binding message}" headercontainerstyle="{staticresource cells}"></gridviewcolumn> <gridviewcolumn header="date" displaymemberbinding="{binding date}" headercontainerstyle="{staticresource cells}"></gridviewcolumn> </gridview> </listview.view> </listview> </grid>
the isenabled
trigger fine ismouseover
trigger not work. tried use controltemplate
there no property <gridviewcolumn/>
, returns error cannot convert controltemplate type datatemplate or style
.
i trying change style of grid header, when on mouseover default template showing.
how can override style?
your trigger working fine, not seeing expect,you need to set contoltemplate
within setter such as
<trigger property="ismouseover" value="true"> <setter property="template"> <setter.value> <controltemplate targettype="{x:type gridviewcolumnheader}"> <border borderbrush="#ff00b9ff" background="#ff00b9ff"> <textblock padding="5,5,5,5" text="{templatebinding content}" textalignment="center" /> </border> </controltemplate> </setter.value> </setter> <setter property="padding" value="2"></setter> </trigger>
also note can set columnheaderstyle once in gridview rather setting multiple time headers, such as:
<gridview allowscolumnreorder="false" columnheadercontainerstyle="{staticresource cells}">