绑定到itemscontrol的UIElement集合,显示在画布中 [英] UIElement collection bound to itemscontrol, displayed in canvas
本文介绍了绑定到itemscontrol的UIElement集合,显示在画布中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我有一个ItemsControl,绑定了一个集合矩形UI元素.这些显示在画布的ItemsPanelTemplate中.我想知道是否可以在画布上的不同位置显示此集合中的矩形.
顺便说一句,我有能力在运行时添加矩形,并希望它们显示在画布中,但不能彼此重叠.
最终,我希望能够在画布上调整这些矩形的大小并将其拖动.
谢谢!
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!
推荐答案
我通过将Point类型的"Position"属性添加到这些UI元素公开的ViewModel类中,解决了此问题.然后,按照此站点的说明,为我的ItemsControl ItemContainerStyle编写了一种样式,该样式将Canvas的Left/Top属性绑定到ViewModel中的属性: ^ ]
当我在画布上拖动这些元素时,还没有弄清楚如何更新ViewModel的位置.
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.
这篇关于绑定到itemscontrol的UIElement集合,显示在画布中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文