从 Silverlight 4 中的代码隐藏更改 DataGridCell 的背景
我正在编写一个 silverlight 应用程序,可让您通过输入的分隔符解析复制的文本。数据被解析并放入网格后,用户就可以“清理”数据。这会将单元格的当前值与列的允许值进行比较,选择最佳猜测并通过 ItemsSource 属性将数据重新绑定到网格。
我的问题是我知道已“擦洗”的每个单元格的坐标,并且我想突出显示该单元格或更改其背景颜色。据我所知,您可以单独设置DataGridCell的背景,但我无法访问DataGridCell。我可以访问网格的列和行,但这些似乎也无法像我希望的那样访问 DataGridCell。设置 ItemsSource 后是否有人可以访问 DataGridCell?
I am writing a silverlight app that lets you parse copied text via entered delimiters. After the data is parsed and dropped into the grid, the user has the ability to "Scrub" the data. This compares the current value of a cell to the allowed values for the column, picks its best guess and rebinds the data to the grid via the ItemsSource property.
My problem is that I know the coordinates of each cell that has been "Scrubbed", and I would like to highlight this cell or change its background color. As far as I can see, you can set a DataGridCell's background individually, but I have no way to access the DataGridCell. I have access to the Grid's columns and rows, but these also do not appear to give access to the DataGridCell as I had hoped. Does anyone have a way to access a DataGridCell after the ItemsSource has been set?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果循环遍历 ItemsSource 绑定到的集合,则可以获取每一行并遍历列以获取内容和单元格 - 类似这样(技巧是 content.Parent 作为 DataGridCell):
If you loop through the collection your ItemsSource is bound to, you can then take each row and go through the columns getting the content and cell - something like this (trick is the content.Parent as DataGridCell):
此代码对于更改单元格的颜色很有用。
This code is useful to change the color of the cell.