We have a user control with context menu on one of its child controls.
The Command is bound to a RelayCommand in the ViewModel.
However, the command has to act on another child control in the View.
What is the best way to do this? I have tried passing the desired child control as a parameter, but I think the syntax is incorrect:
<Controls:ContextMenu >
<Controls:MenuItem Header="Center" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" >
<GalaSoft_MvvmLight_Command:EventToCommand
Command="{Binding RecenterCommand}"
CommandParameter="{Binding ElementName=scrollViewer}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Controls:MenuItem>
</Controls:ContextMenu>
The command:
RecenterCommand = new RelayCommand<ScrollViewer>(Recenter);
private void Recenter(ScrollViewer obj)
{
}
When I use the context menu, Recenter() is called, but the obj param is null.
What is the correct syntax for the ElementName attribute in the CommandParameter binding?
UPDATE: I tried changing the CommandParameter to:
CommandParameter="{Binding ElementName=LayoutRoot, Path=scrollViewer}"
...but still doesn't work.
Thanks for any insights....