本文介绍了如何动态地将图像拖放到画布上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在画布上显示图像

  void  Stickers1_SelectionChanged( object  sender,SelectionChangedEventArgs e)
{

var selecteditem = e。 AddedItems [ 0 ] as StickersImageListModel;

{
Stickers1.Visibility = Visibility.Collapsed;
图片imageitem = Image();
BitmapImage image = new BitmapImage( new System.Uri(selecteditem.Imageurl,UriKind.Absolute ));
imageitem.Source = image;
my_canvas.Children.Add(imageitem);
imageitem.AllowDrop = true ;
}
my_canvas.Visibility = Visibility.Visible;
}





现在我想将这些图片拖放到我的画布上请帮我这样做。



我尝试了什么:



我试过这个

  class  StickersDisplayed 
{
public int id { get ; set ; }
public string Imageurl { get ; set ; }
}

private void my_canvas_ManipulationDelta( object sender,ManipulationDeltaRoutedEventArgs e)

{


if ((e.Position.X > Canvas.GetLeft(_img)&& e.Position.X < Canvas.GetLeft(_ img)+ _img.Width)
||(e.Position.Y > Canvas.GetTop(_img )&& e.Position.Y < Canvas.GetTop(_img)+ _img.Height))
{
{
Canvas.SetLeft(_img,e.Position.X);
Canvas.SetTop(_img,e.Position.Y);
}
}
}
解决方案

I have use the following code to display the images on canvas

                                                             void Stickers1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

    var selecteditem = e.AddedItems[0] as StickersImageListModel;

    {
        Stickers1.Visibility = Visibility.Collapsed;
        Image imageitem = new Image();
        BitmapImage image = new BitmapImage(new                             System.Uri(selecteditem.Imageurl, UriKind.Absolute));
        imageitem.Source = image;
        my_canvas.Children.Add(imageitem);
        imageitem.AllowDrop = true;
    }
    my_canvas.Visibility = Visibility.Visible;
}



now i want to drag and drop these images on my canvas please help me to do this.

What I have tried:

I have tried this

class StickersDisplayed
{
    public int id { get; set; }
    public string Imageurl { get; set; }
}

private void my_canvas_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)

{


    if ((e.Position.X > Canvas.GetLeft(_img) && e.Position.X < Canvas.GetLeft(_img) + _img.Width)
       || (e.Position.Y > Canvas.GetTop(_img) && e.Position.Y < Canvas.GetTop(_img) + _img.Height))
    {
        {
            Canvas.SetLeft(_img, e.Position.X);
            Canvas.SetTop(_img, e.Position.Y);
        }
    }
}
解决方案


这篇关于如何动态地将图像拖放到画布上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 02:04