C
C#•2y ago
binstarjs

Microsoft.Xaml.Behaviors.Wpf MouseMove event passing event args to command is passing null

I have wpf application view. It is capturing MouseMove event, which is sending MouseEventArgs as the argument of the event. Here i am handling that event using Microsoft.Xaml.Behaviors.Wpf inside <i:InvokeCommandAction> tag of the XAML file, wire it to my command of my viewmodel, and setting the PassEventArgsToCommand property to true. This means the MouseEventArgs from the event should be passed to my command argument. However, when i'm trying to run it and when it invokes the command (when i move the mouse), the command argument is null and ofc it throws nullreference exception when im dereferencing the argument. My guess this is a bug unless if im missing something. So how to fix the event to not pass null to my command? (which should pass MouseEventArgs) My view (only relevant lines shown here)
<i:EventTrigger EventName="MouseMove">
<i:InvokeCommandAction Command="{Binding MouseMoveCommand}"
PassEventArgsToCommand="True"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseMove">
<i:InvokeCommandAction Command="{Binding MouseMoveCommand}"
PassEventArgsToCommand="True"/>
</i:EventTrigger>
My viewmodel, which has the command (only relevant lines shown here)
private void OnMouseMove(object? arg)
{
MouseEventArgs e = (MouseEventArgs)arg; // args or e is null, here i need that MouseEventArgs
}
private void OnMouseMove(object? arg)
{
MouseEventArgs e = (MouseEventArgs)arg; // args or e is null, here i need that MouseEventArgs
}
2 Replies
binstarjs
binstarjs•2y ago
I apology for the trouble but it seems it is my fault. When event other than MouseMove is fired (say, MouseEnter), it fires MouseMoveCommand which is mistaken 😅 . I duplicated those tags cuz i don't want to type them one-by-one and i forget to wire up which event goes to which command
Accord
Accord•2y ago
✅ This post has been marked as answered!