Basically, you need to use a RelativeSource
binding. The standard way is to find the ancestor (or parent) of the control of a certain type:
{Binding DataContext.PropertyName, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type YourViewsNamespace:YourParentView}}}
Assuming your parent view has a view model set to its DataContext
, this binding will have access to it ... DataContext
is a DataContext
view, for example. view model defined as DataContext
. Therefore, the PropertyName
property is a public property of this view model.
Regarding the portion of your question that has been asked so many times, check out the following links (or just search the web):
Context menus in WPF
Binding ContextMenu to its logical parent
source share