So I have a WPF DataGrid
, which is bound to an ObservableCollection
. The collection has validation on its members, through IDataErrorInfo
. If I edit a cell in a way so as to be invalid, and then tab away from it before hitting enter, then come back and make it valid, the cell will stop showing invalid, however, the "!" at the head of the row will still be there, and the ToolTip
will reference the previous, invalid value.
相关问题
- VNC control for WPF application
- Date with SimpleDateFormat in Java
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
I have used this technique which do away with RowValidationRules and instead use the property validations in a viewmodel. This requires static variables and data annotations :
My solution was to implement custom row validation feedback, similar to this page under the To customize row validation feedback section. The row error then disappears appropriately.
(I also added
RowHeaderWidth="20"
to theDataGrid
definition, to avoid the table shift to the right the first time the exclamation point appears.)Ok, after some work an alteration of synergetic's solution worked for me, this is how I implemented it:
Don't forget to reference the BooleanToVisibilityConverter:
Just the row style does not (yet) look as good as the default one, I'm working on it.
Edit: Plz help here
I am not using
IDataErrorInfo
orINotifyDataErrorInfo
and my solution was to change my bindings fromUpdateSourceTrigger="PropertyChanged"
toUpdateSourceTrigger="LostFocus"
This was the only thing thatIf you are using ValidationRules in your DataGrid column defintion and you need the validation rules to run when ever the property changes (in the UI or the property) look into setting
ValidatesOnTargetUpdated="True"
on yourValidationRule
XAML Example:
In my case, it worked all well and good when we were using the DataGrid WPF3.5 version. We upgraded to 4.0, then it stopped resetting. After searches on SO, google etc, I chanced upon my solution. Setting UpdateSourceTrigger=PropertyChanged on the Binding in the DataGridTextColumn fixed it for me.
I just realised that the red exclamation mark does not clear on setting it to a correct value.
In my case I had to remove from binding definition
For me it works with both of these definitions:
And
Validation:CellDataInfoValidationRule is custom class & get it here
And your data object must implement IDataErrorInfo