xaml - WPF default TextBox ContextMenu styling -


summary: global "contextmenu" style doesn't applied default context menu on textboxes, , other controls.

specifics: i've got few textboxes in application don't have explicit contextmenu. when right click on them see standard context menu options of cut, copy, , paste. however, context menu doesn't end using global "contextmenu" style i've set in generic.xaml. default context menu on textbox not contextmenu?

if explicitly set contextmenu of textbox, menu uses global contextmenu style. example, works fine:

<style targettype="{x:type textbox}">     <setter property="contextmenu" value="{staticresource standardcontextmenu}"/> </style>  <contextmenu x:key="standardcontextmenu">     <menuitem header="cut" command="applicationcommands.cut"/>     <menuitem header="copy" command="applicationcommands.copy"/>     <menuitem header="paste" command="applicationcommands.paste"/> </contextmenu> 

but don't want have create entirely redundant contextmenu wpf apply style. plus, there other controls besides textbox show contextmenus when clicked, , don't pick global contextmenu style either.

so, what's getting displayed when right-click textbox doesn't have explicit contectmenu defined? thing not contextmenu? why doesn't use global contextmenu style?

edit: looking further using snoop, found when explicitly add contextmenu, it's shown contextmenu in visual tree. default contextmenu gets displayed shown editorcontextmenu in visual tree. next question, then, how style editorcontextmenu globally.

context menus

you're stuck creating custom contextmenu since styling indeed unsupported and, far know, impossible. however, i'd recommend define each item's command , no explicit header text:

<contextmenu x:key="textboxcontextmenu">     <menuitem command="cut"/>     <menuitem command="copy"/>     <menuitem command="paste"/> </contextmenu> 

defining command automatically set header text , shortcut keys in user´s system language.

also, don´t forget apply context menu on passwordbox, combobox , other text editing controls. luck!


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -