We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


How Drop an imahe inside a Grid?

bish wakim
bish wakim asked
Medium Priority
Last Modified: 2013-11-12
I have build a chess board from a Silverlight Grid control .The 64 squares are painted  by
creating 8 rows and 8 columns. I also have png images for the pieces. When I drag by the mouse a piece(png image) and drop it inside the board I would like the droped piece
to be inserted to the appropriate cell which is under the droped piece so that this piece will be a child of the grid. how can I do that?  
Watch Question

Hi, I would suggest using a Uniform grid instead of a grid, just because a UniformGrid will automatically order 64 items in a 8x8 pattern.

You can also define it the number of Columns and Rows in XAML.

However, using a Grid/UniformGrid isn't enough. Something need to catch the Drop event. Although you can probably do it the way you want, I'm suggesting a different way.

Have an ItemsControl.
Make the ItemsPanel of the ItemsControl to be a UniformGrid .

Bind the ItemsControl ItemsSource to an ObservableCollection of your own class that represents a cell.
Have your ObservableCollection contain 64 cell items.

Define a DataTemplate for your Cell class, so it will be shown on the UI as you would like (For example, border with either black or white background).

On Drop, get the item the mouse was over.

Have the picture added to the content of the cell.


Thank you saraqani for your answer
Your suggestion seems to be interesting, However I couldn't find the UniformGrid in Silverlight packages... What do you think?
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview


Thank you!!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.