drag image
-
In window form i can create 1 image and drag it from 1 place to another by: Image_MouseDown, Image_MouseMove and Image_MouseUp but in WPF i make 1 grid(create 5 row and 5 column) and i add child (image) to row 2 and column 2 then 1 make same events but i can't drag it. please make a solution . Thank.Sorry for my english !
-
In window form i can create 1 image and drag it from 1 place to another by: Image_MouseDown, Image_MouseMove and Image_MouseUp but in WPF i make 1 grid(create 5 row and 5 column) and i add child (image) to row 2 and column 2 then 1 make same events but i can't drag it. please make a solution . Thank.Sorry for my english !
It works the same way, the only thing is, the way that things are laid out in WPF is a little different. What have you tried ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
It works the same way, the only thing is, the way that things are laid out in WPF is a little different. What have you tried ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
The grid have 5 ColumnDefinitions and 5 RowDefinitions. If image i can get current Column and Row by GetValue(Grid.RowProperty) and GetValue(Grid.ColumnProperty) . But i don't know how to get current Column and Row of Mouse. If know i can SetValue. Thank !
-
The grid have 5 ColumnDefinitions and 5 RowDefinitions. If image i can get current Column and Row by GetValue(Grid.RowProperty) and GetValue(Grid.ColumnProperty) . But i don't know how to get current Column and Row of Mouse. If know i can SetValue. Thank !
Oh, you want to know what column and row the mouse is over ? I'd imagine you'd need to turn the rows and columns into pixel positions to calculate that, but then, if you caught the mouse move event in each grid square, you could just track which square control got the event last.....
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Oh, you want to know what column and row the mouse is over ? I'd imagine you'd need to turn the rows and columns into pixel positions to calculate that, but then, if you caught the mouse move event in each grid square, you could just track which square control got the event last.....
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
The grid doesn't really have grid squares. It has column/row definitions that define the grid squares. These definitions are used to layout elements "in" the grid squares. So put elements in the grid squares, and subscribe to events on those elements.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
The grid doesn't really have grid squares. It has column/row definitions that define the grid squares. These definitions are used to layout elements "in" the grid squares. So put elements in the grid squares, and subscribe to events on those elements.
Mark Salsbery Microsoft MVP - Visual C++ :java:
Thanks for explaining that a bit better than I did :-)
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Thanks for explaining that a bit better than I did :-)
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
I've got your back. Gives you more time to focus on NullReferenceException issues. ;P
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I've got your back. Gives you more time to focus on NullReferenceException issues. ;P
Mark Salsbery Microsoft MVP - Visual C++ :java:
I have a grid gr and divided it into 5 row, 5 column and placed a Image in it
Image tem = new Image();
tem.Source = new BitmapImage(new Uri("..."));
gr.Children.Add(tem);
tem.SetValue(Grid.ColumnProperty,0);
tem.SetValue(Grid.RowProperty,0);tem.MouseLeftButtonDown += new MouseButtonEventHandler(tem_MouseLeftButtonDown);
tem.MouseLeftButtonUp+= new MouseButtonEventHandler(tem_MouseLeftButtonUp);
tem.MouseMove += new MouseButtonEventHandler(tem_MouseMove);Now, i want to make tem_MouseLeftButtonDown, tem_MouseLeftButtonUp, tem_MouseMove to move Image from (row=i,column=j) to (row=Mouse point,column=Mouse point), in window form i can but in wpf i can't. Sorry for my english. Thank :-O
-
I have a grid gr and divided it into 5 row, 5 column and placed a Image in it
Image tem = new Image();
tem.Source = new BitmapImage(new Uri("..."));
gr.Children.Add(tem);
tem.SetValue(Grid.ColumnProperty,0);
tem.SetValue(Grid.RowProperty,0);tem.MouseLeftButtonDown += new MouseButtonEventHandler(tem_MouseLeftButtonDown);
tem.MouseLeftButtonUp+= new MouseButtonEventHandler(tem_MouseLeftButtonUp);
tem.MouseMove += new MouseButtonEventHandler(tem_MouseMove);Now, i want to make tem_MouseLeftButtonDown, tem_MouseLeftButtonUp, tem_MouseMove to move Image from (row=i,column=j) to (row=Mouse point,column=Mouse point), in window form i can but in wpf i can't. Sorry for my english. Thank :-O
The Grid control, being a Panel element, is suited for layout of child elements. For what you are doing, it would be much simpler to use another simpler panel like a Canvas and keep track of the cell coordinates yourself. That's just my opinion. You could do it with a Grid, but when I picture the code in my head, it looks way messier than it would be using a canvas.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
The Grid control, being a Panel element, is suited for layout of child elements. For what you are doing, it would be much simpler to use another simpler panel like a Canvas and keep track of the cell coordinates yourself. That's just my opinion. You could do it with a Grid, but when I picture the code in my head, it looks way messier than it would be using a canvas.
Mark Salsbery Microsoft MVP - Visual C++ :java:
Yes, I was thinking that, too. I am assuming he wants the image to jump between cells, not move smoothly, but even then, it makes more sense to track positions than use an actual grid, IMO.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Yes, I was thinking that, too. I am assuming he wants the image to jump between cells, not move smoothly, but even then, it makes more sense to track positions than use an actual grid, IMO.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Agreed. I was thinking mostly of the hit-testing being messy, but looking again, I see that WPF drag and drop could be used with drop targets in each cell to let the framework do a lot of that. That may even be simpler than using a canvas :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I have a grid gr and divided it into 5 row, 5 column and placed a Image in it
Image tem = new Image();
tem.Source = new BitmapImage(new Uri("..."));
gr.Children.Add(tem);
tem.SetValue(Grid.ColumnProperty,0);
tem.SetValue(Grid.RowProperty,0);tem.MouseLeftButtonDown += new MouseButtonEventHandler(tem_MouseLeftButtonDown);
tem.MouseLeftButtonUp+= new MouseButtonEventHandler(tem_MouseLeftButtonUp);
tem.MouseMove += new MouseButtonEventHandler(tem_MouseMove);Now, i want to make tem_MouseLeftButtonDown, tem_MouseLeftButtonUp, tem_MouseMove to move Image from (row=i,column=j) to (row=Mouse point,column=Mouse point), in window form i can but in wpf i can't. Sorry for my english. Thank :-O
Drag & drop is another alternative you could consider... Drag & Drop Explained End to End[^]
Mark Salsbery Microsoft MVP - Visual C++ :java: