Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, I have an ItemsControl with a collection rectangle UI elements bound to it. These are displayed in the ItemsPanelTemplate, in a canvas. I was wondering if it would be possible to display the rectangles in this collection at different points on the canvas.

BTW, I have the ability to add rectangles at runtime and want to have them show up in the canvas, but not on top of each other.

Eventually, I want to be able to resize and drag these rectangles around the canvas.

Thanks!
Posted

1 solution

I solved this problem by adding a "Position" property of type Point to the ViewModel class that these UI elements were exposing. I then wrote a style for my ItemsControl ItemContainerStyle that bound the Canvas's Left/Top properties to the ones in the ViewModel, following instructions from this site: http://drwpf.com/blog/2008/03/25/itemscontrol-i-is-for-item-container/comment-page-1/#comment-2971[^]

Haven't quite figured out how to update the ViewModel's position when I drag these elements around the canvas.
 
Share this answer
 

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