Silverlight DataGrid:加载后动态更改背景颜色

时间:2011-09-10 01:47:36

标签: silverlight datagrid converter

情况如下:

1)我有带数字的单元格。如果数字小于x,则显示为绿色。如果数字大于y,则为红色。

2)我使用Converter来设置加载数据网格时的颜色。这很好。

3)我从C#更改数据源中的数字值,并在数据网格上更新值(如果可见)。

4)不幸的是,转换器没有触发以设置正确的颜色。如果我手动编辑数据网格中的单元格,则会启动转换器。

我可以在数据网格中找到单元格并重置颜色,但这会导致更改后滚动的问题(如预期的那样)。

提前致谢,

麦克

1 个答案:

答案 0 :(得分:0)

我相信您有几种选择,例如:

1)  invoking a property changed notification when the color is changed (for the property your converter is converting).
2)  invoking UpdateLayout()
3)  detaching and reattaching the items source
4)  saving scroll position, performing "find the cell in the datagrid and reset the color ", and then invoking a scroll to the saved scroll position.

如果这些不成功,请告诉我您是否使用PagedCollectionView作为ItemsSource或ObservableCollection。