I’m searching for a way to create a global resource for all windows in my WPF project.
I have various windows with different controls but they should all have the same context menu e.g this context menu for a button:
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="1"/>
<MenuItem Header="More">
<MenuItem Header="2"/>
<MenuItem Header="2" IsCheckable="True"/>
<MenuItem Header="2" IsCheckable="True"/>
<MenuItem Header="2" IsEnabled="False"/>
<MenuItem Header="More">
<MenuItem Header="3"/>
<MenuItem Header="More">
<MenuItem Header="4"/>
</MenuItem>
</MenuItem>
</MenuItem>
</ContextMenu>
</Button.ContextMenu>
should also be possible to use on a label in a own different window.
something like this:
resource file: contextMenu
wpf form 1: use contextMenur resource for button
wpf form 2: use contextMenur resource for label
wpf form 3: use contextMenur resource for combobox
all the resource tutorials that I read only had the resource available in the same window
Add it in the App.xaml file, section
<Application.Resources>.Somewhere else:
(from MCTS Training Kit Windows Applications Development by M.A. Stoecker)
Hence you would put the ContextMenu into the Resources, give it an x:Key, and then write