Silverlight Datagrid 块选择
我们正在尝试向 Silverlight DataGrid 控件添加“块选择”:例如,用户应该能够选择从(第 4 列,第 5 行)到(第 6 列,第 8 行)的单元格矩形。
我们正在做的是保存选区的两个角,并通过设置单元格的背景颜色来直观地指示它。我们在滚动方面遇到了麻烦,因为单元格对象及其格式都会被回收。因此,您向上滚动,当选定的单元格从底部消失时,顶部的单元格条就会被着色!我尝试保存实际单元格对象的列表,并且“新”彩色单元格肯定是相同的 DataGridCell 实例,但内容当然不同。
我们可以通过可视化树来获取滚动条,因此我们最终可能会在垂直滚动条的 ValueChanged 事件处理程序中刷新选择显示。
但我想知道是否有更好的方法。我们不是 Silverlight 专家。有人尝试这样做吗?有没有什么对于 Silverlight 高手来说显而易见而我们甚至没有想到的?
我们不会买任何东西。不幸的是,由于公司官僚主义的原因,这不是一个选择。
We're trying to add "block select" to the Silverlight DataGrid control: The user should be able to select, for example, a rectangle of cells from ( col 4, row 5 ) to ( col 6, row 8 ).
What we're doing is saving the two corners of the selection, and indicating it visually by setting the background color of the cells. We've run into trouble with scrolling, because the cell objects are recycled, along with their formatting. So you scroll up, and as the selected cells vanish off the bottom, bars of cells coming in at the top are colored! I've tried saving a List of the actual cell objects and the "new" colored cells are definitely the same DataGridCell instances, though with different content of course.
We're able to get our hands on the scrollbars via the visual tree, so we'll may end up refreshing the selection display in a ValueChanged event handler for the vertical scrollbar.
But I'd like to know if there's a better way. We're not Silverlight experts. Has anybody tried to do this? Is there anything obvious to a Silverlight whiz that we're not even thinking of?
We're not going to buy anything. For corporate bureaucracy reasons, unfortunately, that's not an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不将其包含在您的视图模型中。我要做的是创建一个交互的嵌套可枚举视图模型,即如果数据网格绑定到 T 的 IEnumerable,其中 T 是代表每一行的视图模型,id 在该视图模型上有类似 IndexSelected 的东西。
然后 id 使用某种 valueconverter 将背景颜色绑定到该 indexselected 属性,
请注意,indexselected 绑定上的转换器参数保存列的索引
,转换器要做的就是检查 indexselected 绑定属性是否等于参数(即列的索引)
Why not include that in you viewmodel. What i would do is create a nested enumerable viewmodel of the interaction, ie if the datagrid is bound to a IEnumerable of T where T is a viewmodel representing each row, id have something like IndexSelected on that viewmodel.
Then id bind the back color using a valueconverter of some sort to that indexselected property,
Notice the converter param on the indexselected binding holds the index of the column
and all the converter will do is check if the indexselected bound property equals the parameter (which is the index of the column)