SL4:需要在ItemsControl中的Item上注册移动(或重画)事件 [英] SL4: need to register for a move (or redraw) event on an Item in an ItemsControl

查看:270
本文介绍了SL4:需要在ItemsControl中的Item上注册移动(或重画)事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在FrameworkElement类中找不到move事件或重绘事件。而Google也没有帮助。所以...

Not finding a move event or redraw event in the FrameworkElement class. And Google not helping either. So...

我有一个由VM中的observable集合填充的自定义ItemsControl。 ItemsControl本身利用

I have a custom ItemsControl populated by an observable collection in the VM. The ItemsControl itself leverages the

<i:Interaction.Behaviors>
    <ei:MouseDragElementBehavior ConstrainToParentBounds="True"/>
</i:Interaction.Behaviors>

行为,所以用户可以拖动整个程序集。

behavior so the user can drag around the whole assembly.

当用户移动装配体时,由于装配移动,因为项目被重新定位,所以我希望每个项目通知。到目前为止,我已经尝试注册了

When the user moves the assembly, I want to be notified by each item as the item is repositioned as a result of the assembly moving. So far I have tried registering for

this.myItem.LayoutUpdated += this.OnSomethingNeedsToUpdate;

但是当我拖动程序集时,似乎没有触发。

but it doesn't seem to fire as I drag the assembly around.

另外

this.myItem.MouseMove += this.OnSomethingNeedsToUpdate;

只有在我将鼠标放入不够好的项目中才有效。因为我正在移动ItemsControl,因此必须将鼠标移动到项目中才能使事件触发。

only works if I mouse into the item which is not good enough. Because I am moving the ItemsControl and then have to go mouse into the item to get the event to fire.

任何想法?我可以在视觉树中的一些祖先看一下OneOfMyDecendantsWasRedrawn事件或类似的形式的帮助吗?再次,当组件移动时,当项目移动时,我会尝试收到通知。

Any ideas? Can I look to some ancestor in the visual tree for help in the form of a OneOfMyDecendantsWasRedrawn event or similar? Again I am trying to be notified when an item moves not be notified when the assembly moves.

推荐答案

我最终写了我关心的各个项目的另一个行为,然后编写了一个LINQ查询,以搜索可视化树,并使用附加到它们的MouseDragElementBehavior查找祖先。该查询找到ItemsControl,因为它是Item的最终父项。然后,我可以按照desried注册Dragging事件。

I ended up writting another behavior for the individual items I care about and then wrote a LINQ query to search up the visual tree looking for ancestors with the MouseDragElementBehavior attached to them. That query found the ItemsControl since it was an eventual parent of the Item. I was then able to register for the Dragging event as desried.

再次感谢Bryant提供解决方案在这里

Thanks again to Bryant for providing the solution over here.

这篇关于SL4:需要在ItemsControl中的Item上注册移动(或重画)事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆