开发者

Silverlight 4 DataGrid validation info

开发者 https://www.devze.com 2023-02-12 11:30 出处:网络
I have an ObservableCollection where T: INotifyDataErrorInfo. If I use the DataGrid in edit mode, and there is an error on the object, beside the exact column displaying a red border, the BACKGROUND o

I have an ObservableCollection where T: INotifyDataErrorInfo. If I use the DataGrid in edit mode, and there is an error on the object, beside the exact column displaying a red border, the BACKGROUND of the ENTIRE ROW goes red.

I want the same functionality, but in readonly mode as well! The problem is, the Data开发者_运维百科Grid doesn't listen for ErrorsChanged event unless it goes into edit mode. How can I fix it? Do I have to subclass DataGrid? (I'd prefer not to, I'd rather use Styles or Behaviors) Where can I access the style of the row's background?

EDIT:

I've tried two new things:

  • I've subscribed to the datagrid's RowLoading event, and subscribed to the Row's Loaded and the DataContext's ErrorsChanged event from there (and unsubscribed on RowUnloading), and tried setting the VisualState of the row from these event handlers based on the validity of the DataContext. However, since setting the visual state doesn't change the actual state of the control so when it has to change states (for example on mouseover or selection) it changes back to Valid.
  • Using the trick I've learned from ComboBoxes (see here), I've tried to bind the DataContext to the DataGridRow.Tag, using row.SetBinding(DataGridRow.TagProperty,new Binding()); (since the Source is the DataContext and the path is the entire object), but absolutely nothing happened, like contrary to my earlier findings with ComboBox controls doesn't necessarily listen for Validation on Every DependencyProperty.

So it's getting less likely that there is a practical solution. Any thoughts?


Have a look at the following question, it might help

C# Silverlight Datagrid - Row Color Change

0

精彩评论

暂无评论...
验证码 换一张
取 消