开发者

WPF: Get specify image from touch

开发者 https://www.devze.com 2023-02-04 12:13 出处:网络
I was added picture as a children to layer called \"canvas\". By the following code: if (addChild) { Image i = new Image();

I was added picture as a children to layer called "canvas". By the following code:

if (addChild)
{
    Image i = new Image();
    BitmapImage src = new BitmapImage();
    src.BeginInit();
    src.UriSource = new Uri(path, UriKind.Absolute);
    src.EndInit();
    i.Source = src;
    i.Width = 200;
    i.IsManipulationEnabled = true;
    double rotAngle = Rand.GetRandomDouble(-3.14/4, 3.14/4);

    i.RenderTransform = new MatrixTransform(Math.Cos(rotAngle), -Math.Sin(rotAngle),
                                                    Math.Sin(rotAngle), Math.Cos(rotAngle), Rand.GetRandomDouble(0, this.Width - i.Width), Rand.GetRandomDouble(0, this.Height - i.Width));

    canvasImages.Add(i);
    canvas.Children.Add(i);
    Canvas.SetZIndex(i, canvas.Children.Count-1);
    addedFiles.Add(path);
    maxZ++;
}

Here is the problem. I'm trying to make an event called "canvas_TouchDown" which can detect the specify picture when I touched it so that it will get the center of that image object.

List<Image> canvasImages = new List<开发者_开发知识库Image>();

private void canvas_TouchDown(object sender, TouchEventArgs e)
{
    foreach (Image canvasImage in canvasImages)
    {
        if (canvasImage.AreAnyTouchesCaptured == true)
        {
            System.Diagnostics.Debug.WriteLine("I found image that you touch");
        }
    }
}

However, there is nothing happened. I also try to use PersistId property but it doesn't work. Have any suggestion?

Regard,

C.Porawat


If you are adding the image to the canvas, touching it and expecting the canvas to receive the touch you will be disappointed. You should either listen to "touch down" on the image or "preview touch down" on the canvas.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号