0

I have implemented a WPF project which renders a 3D mesh of data coming from a micro profilometer.

Since I have already implemented a big part of the work of 2D data analysis on WinForms; I want to create a user control of the WPF class which is called by the winform application. And I did. The problem is that in the WPF class the mouse events are triggered, and I can rotate, zoom, and shift the mesh; but when I insert the user control in my winform application, the mesh is successfully created; but the mouse events aren't triggered at all. (but they are implemented in the user control)

Am I missing some logic?

Here is the code for the WPF mouse events

public void OnViewportMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs args)
{
    Point pt = args.GetPosition(mainViewport);
    if (args.ChangedButton == MouseButton.Left)         // rotate or drag 3d model
    {
        m_transformMatrix.OnLBtnDown(pt);
    }

    }

    public void OnViewportMouseMove(object sender, System.Windows.Input.MouseEventArgs args)
    {
        Point pt = args.GetPosition(mainViewport);

        if (args.LeftButton == MouseButtonState.Pressed)                // rotate or drag 3d model
        {
            m_transformMatrix.OnMouseMove(pt, mainViewport);

            TransformChart();
        }
    }

    public void OnViewportMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs args)
    {
        Point pt = args.GetPosition(mainViewport);
        if (args.ChangedButton == MouseButton.Left)
        {
            m_transformMatrix.OnLBtnUp();
        }

    }
}

And this is the winform that uses the WPF user control

public partial class MeshViewer: Form
{
    wpfControlLib.UserControl1 userControl;
    public MeshViewer(double[,] d)
    {
        InitializeComponent();

        userControl = new wpfControlLib.UserControl1(d);
        elementHost1.Child = userControl;
        elementHost1.Show();

    }
}

I tried to put the same mouse event handlers in the winform class and then call the corresponding mouse events of the WPF class, but the mouse event args are different in WinForms and WPF... and I don't think this is the right path...

Dev
  • 1,780
  • 3
  • 18
  • 46
  • can you show us what you've already tried or the code you currently have? – Anjo Apr 24 '18 at 14:24
  • edited with the mouse event part, thanks. – Nicola Gaburro Apr 24 '18 at 14:36
  • hmm have you tried creating a simple click event on the wpf form and check if it would trigger on your winform? so that we can verify if the problem is the triggering of the event or something else – Anjo Apr 24 '18 at 14:44
  • I tried putting some Console.writeLine in all the wpf mouseEvent code and they never trigger or get visualized. – Nicola Gaburro Apr 24 '18 at 14:54
  • no what i mean is a simple event say Loaded event on your user control, so that we can verify if any event is being triggered. To narrow down where do we look for the problem – Anjo Apr 24 '18 at 15:19
  • check this [question](https://stackoverflow.com/questions/22781031/wpf-mousedown-event-not-firing-everywhere-in-a-control) maybe this can help. Have you tried setting the background of the usercontrol in your wpf? – Anjo Apr 24 '18 at 15:22
  • @Anjo !!!! thanks! Setting the background worked! – Nicola Gaburro Apr 24 '18 at 16:21

0 Answers0