1
private void selectColor_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        xMove += e.DeltaManipulation.Translation.X;
        yMove += e.DeltaManipulation.Translation.Y;

        double xMax = 350;
        double yMax = 40;

        if (xMove < 0)
        {
            xMove = 0;
        }
        else if (xMove > xMax)
        {
            xMove = xMax;
        }

        if (yMove < 0)
        {
            yMove = 0;
        }
        else if (yMove > yMax)
        {
            yMove = yMax;
        }

        int x = Convert.ToInt32(xMove);
        int y = Convert.ToInt32(yMove);

        var writeableBmp = new WriteableBitmap(selectColor, null);
        var tempColor = writeableBmp.GetPixel(x, y);
        Brush imageColor = new SolidColorBrush(tempColor);

        txtBlockName.Foreground = imageColor;
    }

This function is for handling the manipulationDelta when i tap and drag inside the canvas called selectColor. yMove and xMove are 2 doubles that record the total movement. they are declared prio to the function. As the title states i get a IndexOutOfRangeException, and it points at x. I dont see how that is possible since i have set max/min values that are within the canvas. My canvas is exactly 350x40, so when x = 180 it shouldn't give me this error. I am a little confused right now, any help/advice will be appreciated.

1 Answer 1

2

Set the limits to

    double xMax = 349;
    double yMax = 39;

0 .. 349 = 350 pixels
0 .. 39 = 40 pixels

You are off-by-one when you set the xMove and yMove to the actual max values

Sign up to request clarification or add additional context in comments.

2 Comments

thanks man, overlooked that completly. fixed the issue, will accept answer the moment i can
Overlooked the tag winphone8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.