Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have use the following code to display the images on canvas
C#
                                                             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
C#
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);
        }
    }
}
Posted
Updated 6-Jun-16 5:18am
v2

1 solution

This is a Microsoft sample demonstrating it: https://msdn.microsoft.com/en-us/library/bb295243%28v=vs.90%29.aspx[^].

See also this CodeProject article: Dragging Elements in a Canvas[^].

—SA
 
Share this answer
 
Comments
vikas sharawat 6-Jun-16 4:14am    
background property is not applicable in DragCanvas.
and in my case i have a background images also.
and I want to drag and drop only stickers on my canvas.
Sergey Alexandrovich Kryukov 6-Jun-16 11:16am    
Why do you mention "background property" at all? It's not the part of your original question. If you want to have some background, have it. Of course Canvas has the background property.

You can drag and drop any UI elements on your canvas, "stickers" or not. What's the problem? I answered your question in full. Will you accept the answer formally?

—SA
vikas sharawat 7-Jun-16 0:37am    
dear sir it gives error DragCanvas is not supported in windows appp project
Sergey Alexandrovich Kryukov 7-Jun-16 1:10am    
What are you talking about? Is it about the class DragCanvas of the CodeProject article I mentioned?
Why would you assume that it should be supported? Download the code of this article and see how it works...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900