Hi there,

I have a WinForm application written in C#. I have added a WPF usercontrol added to the Winform and I want to get the mouse Events passed back to the WinForm.

So you can see in line 6, my XAML I have a MouseUp event:

UserControl x:Class="CustomRssFeed.MainWin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="41" Width="699" Foreground="#FFFFFFFF" Loaded="MainWin_Loaded" Unloaded="MainWin_Unloaded"
SizeChanged="MainWin_SizeChanged"
MouseUp="UserControl_MouseUp"

and I have a XAML.CS with:

private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
{
           
}

My question is how do I convert the 'MouseButtonEventArgs e' to a friendly WinForm version of MouseEventArgs ???

>how do I convert the 'MouseButtonEventArgs....?
Class MouseButtonEventArgs is a subclass of MouseEventArgs.

private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
{
   MouseEventArgs ee=e;  //Boxing
}

Thanks for the reply but I still get the compile error:

Cannot implicitly convert type 'System.Windows.Input.MouseButtonEventArgs' to 'System.Windows.Forms.MouseEventArgs'

Just add the cast explicitly:

MouseEventArgs ee = (MouseEventArgs)e;

yep, I tried casting too and I get:

Cannot convert type 'System.Windows.Input.MouseButtonEventArgs' to 'System.Windows.Forms.MouseEventArgs'

Try this:

System.Windows.Input.MouseEventArgs ee = (System.Windows.Input.MouseEventArgs)e;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.