I'm trying to send property thats set by dp to my viewmodel (bound via datacontext) via command parameter a Dependency Property in the code behind of my view. The property (ParentUserControl) seems to be initialized correctly when breaking into it, however I can't seem to be able to send it. I've tried the two bindings below
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding CommandTest}"
CommandParameter="{Binding ParentUserControl, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MyView}}}" />
</ContextMenu>
</DataGrid.ContextMenu>
and
<ContextMenu>
<MenuItem Command="{Binding CommandTest}"
CommandParameter="{Binding ParentUserControl, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" />
</ContextMenu>
I'm using mvvmlight relay commands as shown below however the parameter pased in the method test() is always null
CommandTest = new RelayCommand<object>(x => test(x));
This is the dependency property attached in the code behind of the view:
public static readonly DependencyProperty ParentUserControlProperty = DependencyProperty.Register(
"ParentUserControl", typeof(UserControl), typeof(MyView), new PropertyMetadata(default(UserControl)));
public UserControl ParentUserControl
{
get { return (UserControl) GetValue(ParentUserControlProperty); }
set { SetValue(ParentUserControlProperty, value); }
}