如何将事件处理程序附加到使用 WPF 中的数据绑定生成的项目?
我正在为 MS Surface 设备进行开发,并使用 ScatterView
来显示一些数据。 下面的场景可能也适合普通的 ListBox
(和 ListBoxItems
)。
当我对 ScatterView
进行数据绑定时,WPF 会自动使用 ScatterViewItems
包装 DataTemplate
的内容。 我想为(生成的)ScatterViewItem
的 ScatterManipulationCompleted
事件附加一些事件处理程序,但不知道如何做到这一点。
任何帮助深表感谢。
I am developing for a MS Surface unit and am using a ScatterView
to display some data. The scenario below probably fits a normal ListBox
(and ListBoxItems
) too.
When I databind the ScatterView
, WPF automatically wraps the contents of the DataTemplate
with ScatterViewItems
. I want to attach some event handers for the ScatterManipulationCompleted
event of the (generated) ScatterViewItem
, but can't figure out how to do that.
Any help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在容器类型上设置
Style
并指定EventSetter
,如下所示:You can set a
Style
on the container type and specify anEventSetter
like this:您应该利用路由事件。 您只需在 ScatterView 级别监听此事件即可。
You should take advantage of routed events. You can just listen for this event at the ScatterView level.
正如经常发生的那样,我现在找到了答案。 我在过去 20 个小时左右的时间里一直在研究这个问题,只是在发布问题 5 分钟后才找到它:-(
无论如何:我找到的解决方案并且目前对我有帮助的是使用 ScatterView 的 Loaded 事件在处理程序中,我有以下循环:
在阅读 http:// /www.beacosta.com/blog/?p=7
他人有帮助。
希望这对其
巴特
As so often happens, I now found the/a answer. I've been looking at this for the last 20 hours or so, only to find it 5 minutes after posting the question :-(
Any way: the solution I found and which helps me for now is to use the Loaded event of the ScatterView. In the handler, I have the following loop:
It all came to me after reading http://www.beacosta.com/blog/?p=7
Hope this helps anybody else.
Bye,
Bart