Silverlight DataGrid 垂直滚动条问题
我有一个充满表格的数据网格。现在会出现垂直滚动条,因为表格不适合。到目前为止还好。现在,在最后一列中,我在 xaml 文件中定义了一个按钮。所有这些按钮都有相同的回调,但我可以从表的 selectedIndex 中区分出这个回调应该做什么。因为单击该按钮还会自动选择 DataGrid 中该按钮所在的行。到目前为止还好。现在在我的应用程序中,对于某些行,我想禁用按钮,因为它对该特定行没有意义。所以我所做的是订阅每个按钮的 Load 事件,并让回调设置 MaxWidth = 0(如果按钮没有意义)。这也很好用,但只是最初。一旦我开始拖动滚动条,按钮列中的随机位置就会显示按钮,或者错误的按钮会获得 MaxWidth = 0。我有一种强烈的感觉,在顶部滚动的单元格正在底部被重用,但我没有收到活动,或者至少我不知道应该订阅哪个活动。我不知道如何识别滚动条。有人建议解决这个问题吗?
I have a Datagrid filled with a table. Now the vertical scrollbar shows up because the table doesn't fit. That's fine so far. Now in the last column I have defined a Button in the xaml file. All these buttons have the same callback, but I can distinguish from the selectedIndex of the table what this callback should do. Because clicking the button automatically also selects the line in the DataGrid where this button lives. That's fine so far. Now in my app, for some rows I want to disable the Button, because it has no meaning for that specific row. So what I did is take a subscription on event Load of each Button and let the callback set the MaxWidth = 0, if the button has no meaning. This works fine too, but only initially. As soon as I start dragging the scrollbar, at random places in the Button column buttons show up, or wrong buttons get MaxWidth = 0. I have the strong feeling that cells that scrolled out at the top are being reused at the bottom, but I don't get an event, or at least I don't know which event I should subscribe on. I don't know how to identify the scrollbar. Has anyone a suggestion to tackle this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己终于找到了解决这个问题的方法,贴出来记录一下。
您应该订阅的事件是
LoadingRow
(由DataGrid 生成)。在回调中,
您可以使用 VisualTreeHelper 来识别单元格中的元素,如下所示:
I finally found a solution to this problem myself, and I will post it for the record.
The event you should subscribe on is
LoadingRow
(generated by the DataGrid).In the callback
you can identify an element in a cell by using VisualTreeHelper for instance as follows: