XAML binding groups

I am trying to make a binding group to calculate row validity based on three text fields in a datagrid.

I created a ValidationRule class, and then in my datagrid I:

       <DataGrid.BindingGroup>
          <BindingGroup Name="RowBindingGroup">
             <BindingGroup.ValidationRules>
                <util:MinMaxParValidationRule ValidationStep="CommittedValue" />
             </BindingGroup.ValidationRules>
          </BindingGroup>
       </DataGrid.BindingGroup>

and

<TextBox.Text>
   <Binding Path="ParStockLevel" UpdateSourceTrigger="PropertyChanged" BindingGroupName="RowBindingGroup" />
</TextBox.Text>

My validation rule class looks like

 public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
  {
     ValidationResult result = ValidationResult.ValidResult;
     BindingGroup bindingGroup = (BindingGroup)value;

     StockInformationDVM row = (StockInformationDVM)bindingGroup.Items[0];

Now, when I run the application, the value that is part of the validation rule class is always the first row in my datagrid, the row never checked (unless you check the first row!)

I have not done this before, and the examples that I find arent using MVVM there may be problems.

+3
source share
1 answer

Try specifying the binding group as DataGrid.ItemBindingGroupinstead of DataGrid.BindingGroup:

<DataGrid.ItemBindingGroup>
   <BindingGroup>
      <BindingGroup.ValidationRules>
         <util:MinMaxParValidationRule ValidationStep="CommittedValue" />
      </BindingGroup.ValidationRules>
   </BindingGroup>
</DataGrid.ItemBindingGroup>

. .

+1

Source: https://habr.com/ru/post/1795797/


All Articles