Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Two questions about BindingGroup

$
0
0

Hi,

in my application I have a DataTemplate for a TabControl defined in a xaml loaded at runtime.
In this template there are 10 text boxes and I have to check they don't contain the same numbers.
So I'm trying to use BindingGroup in the following way:

[XAML (only relevant part)]

<DataTemplate
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:CPS;assembly=CPS"
    xmlns:props="clr-namespace:CPS.Properties;assembly=CPS"><DataTemplate.Resources>    <local:StringConverter x:Key="StrConverter" />   <XmlDataProvider x:Key="dataProvider" />    </DataTemplate.Resources><Grid Margin="0 50 100 0"><Grid.BindingGroup><BindingGroup Name="DGNA_BindingGroup" ><BindingGroup.ValidationRules><local:DGNAValidationRule ValidatesOnTargetUpdated="True" 
                                    ValidationStep="UpdatedValue" /></BindingGroup.ValidationRules></BindingGroup></Grid.BindingGroup><TextBox Name="TextBox_1" Grid.Row="1" Grid.Column="1"
             IsEnabled="{Binding ElementName=CheckBox_EnableDGNA, Path=IsChecked}"
             DataContext="{StaticResource dataProvider}"
             Style="{StaticResource textBoxInError}" ><TextBox.Text><Binding XPath="BLOCK[@id=1]/ITEMS/ITEM[(@id=14) and (@index=0)]/@value"
                 UpdateSourceTrigger="PropertyChanged"
                 Converter="{StaticResource StrConverter}"
                 NotifyOnValidationError="True"
                 ValidatesOnExceptions="True"
                 BindingGroupName="DGNA_BindingGroup"><Binding.ValidationRules><local:RangeValidator Min="0" Max="16776415"/></Binding.ValidationRules></Binding></TextBox.Text></TextBox></Grid></DataTemplate>

The window is composed by a ToolBar and a TabControl which ItemSource is a collection of my Tab classes (defined in code).
When I start the application the DGNAValudationRule is called:

  public class DGNAValidationRule : ValidationRule {
    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo) {
      BindingGroup bg = value as BindingGroup;

      foreach (object item in bg.Items) {
        System.Diagnostics.Debug.WriteLine(item.ToString());
      }
      return ValidationResult.ValidResult;
    }
  }

and the bg.Items[0] is an instance of a Tab class.....why?

Is there a way to access the TextBoxes within the Validation method?

Also, the validation method is called only at startup, how can I make it called every time I made a change?

Regards,
Daniele.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>