I have a problem with linking buttons on an item. I have a Haml:

<MediaElement.InputBindings> <KeyBinding Command="{Binding Path=KeyPressedCommand}" CommandParameter="{Binding}" Key="Enter" /> </MediaElement.InputBindings> 

And ViewModel:

 public RelayCommand KeyPressedCommand { get; set; } ... KeyPressedCommand = new RelayCommand(x => KeyPressed(x)); ... private void KeyPressed(object mediaElement) { Watch.Stop(); (mediaElement as MediaElement).Stop(); MessageBox.Show(Watch.Elapsed.Seconds.ToString()); } 

For example.

But for some reason it does not work out the event when I press the Enter button. I tried differently:

 <MediaElement.InputBindings> <MouseBinding Command="{Binding Path=KeyPressedCommand}" MouseAction="RightClick" CommandParameter="{Binding}" /> </MediaElement.InputBindings> 

Everything works out as it should.

The output does not write any errors. But the problem is that I need to hang up the Enter key handler.

I tried through this approach:

 <i:Interaction.Triggers> <i:EventTrigger EventName="KeyDown"> <i:InvokeCommandAction Command="{Binding Path=KeyPressedCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MediaElement}}" /> </i:EventTrigger> </i:Interaction.Triggers> 

Also zero result.

  • one
    and the element in focus? When you click the mouse, he gets the focus, and when you click on the enter, this does not happen by itself - vitidev
  • Hmm, strange, like I had the line: (mediaElement as MediaElement). Focus (); I added this to the haml: Focusable = "True" And everything began to work. Thank. - bodynar

0