Silverlight中的复选框DataGrid行为奇怪 [英] Checkbox in silverlight DataGrid behaving strangely

查看:117
本文介绍了Silverlight中的复选框DataGrid行为奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Silverlight 5 DataGrid 中的 itemtemplate 列中使用复选框
我面临一个奇怪的问题。当我选择多个复选框,然后向上和向下滚动网格时,选择切换到某些其他复选框

I am using checkbox in an itemtemplate column in a Silverlight 5 DataGrid. I am facing a strange problem with it. When I select more than one checkbox and then scroll the grid up and down, the selection shifts to some other checkbox.

推荐答案

这是一个已知的行为,因为Silverlight正在重新使用其在DataGrid中的图形资源。在此Silverlight主题中有一个讨论。

This is a known behaviour since Silverlight is re-using its graphical resources in the DataGrid. There's a discussion about it in this Silverlight thread.

看来一个办法是修改IsSelected属性:

It seems one way to fix it is to databind the IsSelected property:


在我的数据源中添加一个新属性:
IsSelected,并将复选框绑定到该值。

My solution at that time was to add a new property in my data source: IsSelected, and to bind the checkbox to that value.

更多其他信息在此主题,其中Microsoft回答:

You have more additional info in this thread, where Microsoft answers:


这不是一个错误。当你在
中滚动时发生什么DataGrid是相同的复选框用于新数据,因为
DataGrid回收的视觉效果。当您的新数据具有不同的
值时,检查将通过绑定更改,您将收到
事件。你可以做什么来使这个场景工作是听
到LoadingRow,当一个行进入视图时引发。在那里,
你可以调用column.GetCellContents来获取单元格的内容。
这将给你的CheckBox,你可以附加到CheckChanged在
这一次。如果你这样做,你需要做类似的事情,
听UnloadingRow,所以你可以分离的事件处理程序时
复选框滚动出来的视图。

This is not a bug. What happens when you scroll around in the DataGrid is the same checkboxes are being used for new data because the DataGrid recycles the visuals. When your new data has different values, the check will change through the Binding and you'll receive the event. What you can do to get this scenario to work is to listen to LoadingRow which is raised when a row comes into view. In there, you can call column.GetCellContents to get the contents of the cell. This will give you the CheckBox, and you can attach to CheckChanged at this time. If you do this, you need to do something similar and listen to UnloadingRow so you can detach the eventhandler when the checkbox is scrolled out of view.

这篇关于Silverlight中的复选框DataGrid行为奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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