0

So I try to pass informations from my MainWindow.xaml.cs to a new Window called Distance.xaml.cs. Therefore I added a button, which opens the new Window, when clicked. My Code nearly perfectly works:

    private void CmdDistance_Click(object senderr, RoutedEventArgs e)
    {
        Distance distance = new Distance();
        distance.setPosition(e.GetPosition(DepthImage));
        distance.setArray(mySkeletonArray);
        distance.Show();
    }

The only problem is that I need to pass the Position on DepthImage to Distance.xaml.cs. So I use GetPosition. But here's my problem: To use GetPosition I need to use System.Windows.Input.MouseEventArgs, but if I program two EventHandler to my function I get the error:

No overload for 'CmdDistance_Click' matches delegate 'System.Windows.RoutedEventHandler'

Does anybody know what I'm doing wrong

Edit: I now changed my code, so that I first store the mouse position in a variable, and the pass it to the second window. The problem is that when I try to mark two point in my image nothing is passed from MainWindow to the second window, and therefore nothing happens.

Here is my new code for MainWindow:

    public partial class MainWindow:Window
    {
    System.Windows.Point myMousePosition;

    private void MousePosition(object sender, System.Windows.Input.MouseEventArgs e)
    {
            System.Windows.Point myMousePosition = e.GetPosition(DepthImage);
    }

    private void CmdDistance_Click(object senderr, RoutedEventArgs e)
    {
        Distance distance = new Distance();
        distance.setPosition(myMousePosition);
        distance.setArray(mySkeletonArray);
        distance.Show();
    }
    }

In the DistanceWindow I use this lines of code to calculate the distance:

    public partial class Distance : Window
    {
    KinectSensor mySensor;
    SkeletonPoint[] mySkeletonArray;
    System.Windows.Point position;

    int i;

    public Distance()
    {
        InitializeComponent();

        i = 1;
    }

    public void setPosition(System.Windows.Point pos)
    {
        position = pos;
    }

    public void setArray(SkeletonPoint[] SkeletonArray)
    {
        mySkeletonArray = SkeletonArray;
    }

    private void DistanceMeasurement(object sender, System.Windows.Input.MouseEventArgs e)
    {
            int xpos = (int)position.X;
            int ypos = (int)position.Y;
    }
    }
user3794592
  • 183
  • 2
  • 16
  • as button click event handler gives you RoutedEventArgs where as your GetPosition depends on the point where you get clicked so it will return you System.Windows.Input.MouseEventArgs. I think instead of handling button click event you can handle preview event of button. it might serve your purpose. – Ashok Rathod Jul 31 '14 at 03:52
  • But how do I do this? – user3794592 Jul 31 '14 at 04:05
  • What you're trying to do with `MouseEventArgs.GetPosition()` doesn't make sense (read the documentation to see what the function *actually* do). You may want to try the way explained [in this thread](http://stackoverflow.com/questions/386731/get-absolute-position-of-element-within-the-window-in-wpf) to get position of `DepthImage` relative to the `Window` – har07 Jul 31 '14 at 04:09
  • I know that System.Windows.Input MouseEventArgs.GetPosition() returns the position of the mouse cursor relative to the element, declared in the function. So in my case relative to the DepthImage. That's why I use this function. So I get the pixel number, the user clicked on and a can calculate the distance. I know the function works, the way I need it. But you are right, so I did some changes in my code, shown in the edit of my question – user3794592 Jul 31 '14 at 13:16

0 Answers0