Sunday, 15 August 2010

c# - MenuItem Style override single role style -



c# - MenuItem Style override single role style -

is there way override single role style of menuitem? know way override ishighlighted color of menuitem override contenttemplate. want override contenttemplate role "submenuitem"

<style x:key="actionmenuitemstyle" targettype="{x:type menuitem}"> <setter property="horizontalcontentalignment" value="{binding path=horizontalcontentalignment, relativesource={relativesource ancestortype={x:type itemscontrol}}}" /> <setter property="verticalcontentalignment" value="{binding path=verticalcontentalignment, relativesource={relativesource ancestortype={x:type itemscontrol}}}" /> <setter property="background" value="transparent" /> <setter property="template" value="{staticresource submenuitemtemplatekey2}" /> <setter property="foreground" value="black" /> <style.triggers> <trigger property="role" value="toplevelheader"> <setter property="padding" value="7,2,8,3" /> <setter property="template" value="???" /> <setter property="foreground" value="white" /> </trigger> <trigger property="role" value="toplevelitem"> <setter property="padding" value="7,2,8,3" /> <setter property="template" value="???" /> </trigger> <trigger property="role" value="submenuheader"> <setter property="padding" value="2,3,2,3" /> <setter property="template" value="???" /> </trigger> <trigger property="role" value="submenuitem"> <setter property="padding" value="2,3,2,3" /> </trigger> </style.triggers> </style>

the {staticresource submenuitemtemplatekey2} override contenttemplate. other roles want utilize default templates of menuitem. there way it?

best regards

lutze

you're trying override menu items , next trying override 1 time again (to set default style). in case need override menu item role of submenuitem, code can this:

<style x:key="actionmenuitemstyle" targettype="{x:type menuitem}"> <setter property="horizontalcontentalignment" value="{binding path=horizontalcontentalignment, relativesource={relativesource ancestortype={x:type itemscontrol}}}" /> <setter property="verticalcontentalignment" value="{binding path=verticalcontentalignment, relativesource={relativesource ancestortype={x:type itemscontrol}}}" /> <setter property="background" value="transparent" /> <setter property="foreground" value="black" /> <style.triggers> <trigger property="role" value="toplevelheader"> <setter property="padding" value="7,2,8,3" /> <setter property="foreground" value="white" /> </trigger> <trigger property="role" value="toplevelitem"> <setter property="padding" value="7,2,8,3" /> </trigger> <trigger property="role" value="submenuheader"> <setter property="padding" value="2,3,2,3" /> </trigger> <trigger property="role" value="submenuitem"> <setter property="padding" value="2,3,2,3"/> <!-- override here --> <setter property="template" value="{staticresource submenuitemtemplatekey2}"/> </trigger> </style.triggers> </style>

otherwise (following original approach), may need dummy menuitem element has default style. can bind template of whatever items template of dummy element restore default style.

c# wpf wpf-controls menuitem

No comments:

Post a Comment