Cannot capture Mouse Move on WPF platform
I have a problem to capture mouse move event in my application. I've even tried to capture mouse event in sample application going with LibVLCSharp:
Example2.xaml:
<Window x:Class="LibVLCSharp.WPF.Sample.Example2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:LibVLCSharp.WPF.Sample"
xmlns:uc="clr-namespace:LibVLCSharp.WPF;assembly=LibVLCSharp.WPF"
mc:Ignorable="d"
Title="Example2" Height="450" Width="800">
<Grid>
<uc:VideoView x:Name="VideoView" Panel.ZIndex="1" MouseMove="OnMouseMove" PreviewMouseMove="OnMouseMove">
<StackPanel Orientation="Horizontal" x:Name="test">
<Button Content="PLAY" Height="25" Width="50" VerticalAlignment="Bottom" HorizontalAlignment="Left" Click="PlayButton_Click" />
<Button Content="STOP" Height="25" Width="50" VerticalAlignment="Bottom" HorizontalAlignment="Left" Click="StopButton_Click" />
</StackPanel>
</uc:VideoView>
</Grid>
</Window>
Example2.xaml.cs:
using LibVLCSharp.Shared;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using MediaPlayer = LibVLCSharp.Shared.MediaPlayer;
namespace LibVLCSharp.WPF.Sample
{
public partial class Example2 : Window
{
LibVLC _libVLC;
MediaPlayer _mediaPlayer;
public Example2()
{
InitializeComponent();
var label = new Label
{
Content = "TEST",
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Bottom,
Foreground = new SolidColorBrush(Colors.Red)
};
test.Children.Add(label);
_libVLC = new LibVLC();
_mediaPlayer = new MediaPlayer(_libVLC);
// we need the VideoView to be fully loaded before setting a MediaPlayer on it.
VideoView.Loaded += (sender, e) =>
{
_mediaPlayer.EnableMouseInput = true;
_mediaPlayer.EnableKeyInput = true;
VideoView.MediaPlayer = _mediaPlayer;
};
}
void StopButton_Click(object sender, RoutedEventArgs e)
{
if (VideoView.MediaPlayer.IsPlaying)
{
VideoView.MediaPlayer.Stop();
}
}
void PlayButton_Click(object sender, RoutedEventArgs e)
{
if (!VideoView.MediaPlayer.IsPlaying)
{
VideoView.MediaPlayer.Play(new Media(_libVLC,
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", FromType.FromLocation));
}
}
private void OnMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
}
}
}
The **OnMouseMove **is never called. I tried to set **EnableMouseInput **to true, no help. If I add border to **VideoView **control the mouse move event is captured to border area but not to client area:
` <uc:VideoView x:Name="VideoView" Panel.ZIndex="1" MouseMove="OnMouseMove" PreviewMouseMove="OnMouseMove" BorderBrush="Red" BorderThickness="10">`
Thank you for advice.
Juraj