Workaround for binding expression list on binding group being empty
In WPF 4 the binding expression list on the binding group, which is passed to the ValidationRule
's Validate method, is empty.
It is the same whether AutoGenerateColumns
is true or false, whether DataGridBoundColumns
explicitly has been added to the datagrid.
In WPF 3.5 SP1 using the DataGrid
from the Toolkit the binding expression list is filled with the excepted binding expre开发者_运维知识库ssions (1 for each column in the data grid)
I consider this a bug and has posted it on the Microsoft Connect site: https://connect.microsoft.com/WPF/feedback/details/642815/bindingexpressions-on-bindinggroup-passed-to-validationrule-in-datagrid-rowvalidationrules-is-empty
But does anyone have a workaround so I can get the correct binding expression from within the ValidationRule
?
In order to support "proposed values" that are not committed to the target of a two-way binding until validation succeeds, the WPF 4.0 DataGrid
was redesigned to take advantage of the the new BindingGroup.SharesProposedValues
feature of WPF 4.0. Because of this change, it is no longer necessary to use two-way bindings in binding group of display templates.
You can use BindingGroup.TryGetValue
to retrieve the proposed values for other columns instead of using the old method that worked with the DataGrid
from the WPF Toolkit.
In other words, the new DataGrid
actually fixes an undesirable feature of the old DataGrid
and as a result things work slightly differently (i.e. the missing bindings are by design) but you can still do what you need to do.
The explanation in Microsoft's own words is in this Microsoft Connect link:
- BindingExpressions on BindingGroup passed to ValidationRule in DataGrid.RowValidationRules is empty
And here is a blog that describes BindingGroup.SharesProposedValues
in another way:
- List of features to track in WPF4 and the details on beta1
精彩评论