Suppose I have a context menu as a window resource:
<Window.Resources>
<ContextMenu
x:Shared="false"
x:Key="ContextMenu">
<MenuItem Header="{??}" />
</ContextMenu>
</Window.Resources>
And I want to bind MenuItem.Header to a dependency property called MenuItemHeader on the window. What should {??} be and what should the code behind in the window class look like?
You could name the window and reference it
MyDpbeing the property. If you don’t know how to define a dependency property read the overview.(I would use
Sourceandx:ReferenceasElementNameusually does not work in disconnected places likeContextMenus)