wpf - Background color for MenuItem not changed on MouseOver -


i have menu 3 items , i'm trying change background color when mouse hovers on of items. i've tried ismouseover & ishighlighted trigger property , neither works.

in app.xaml:

<style targettype="menuitem" x:key="menuitemstyle" >         <style.triggers>             <trigger property="menuitem.ishighlighted" value="true">                 <setter property="background" value="black"/>             </trigger>         </style.triggers>               </style> 

in main.xaml:

<menu horizontalalignment="left" height="30" verticalalignment="top" width="975           " fontfamily="tempus sans itc" fontsize="16"  >         <menu.background>             <lineargradientbrush endpoint="0.5,1" startpoint="0.5,0">                 <gradientstop color="#ffc8c8c8" offset="0"/>                 <gradientstop color="black" offset="1"/>             </lineargradientbrush>         </menu.background>         <menu.foreground>             <solidcolorbrush color="#fffffffb"/>         </menu.foreground>         <menuitem header="new" click="menunew_click" verticalalignment="center" padding="15,4,8,3" width="60">             <menuitem.tooltip>                 <tooltip>                     add new park                 </tooltip>             </menuitem.tooltip>         </menuitem>         <menuitem header="search" width="65" padding="12,4,8,3"  >             <menuitem.tooltip>                 <tooltip> select search option</tooltip>             </menuitem.tooltip>             <menuitem header="name" background="black" fontsize="14" style="{staticresource menuitemstyle}" />             <menuitem header="id" background="black" fontsize="14"/>             <menuitem header="ownername" background="black" fontsize="14"/>         </menuitem>               </menu>     

the default controltemplate menuitem (as extracted show me template) doesn't set menuitem.background property on mouse over, sets element in template directly. unfortunately, means won't able change highlight color, you'll have recreate entire controltemplate. msdn has example of how (this 1 .net 3.5 should work 4.0 or 4.5).

one other caveat in code: since you're setting background directly on menuitems, style's trigger not work anyway. because of dependencyproperty value precedence, local value set on items can not overridden style trigger.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -