I have the following code in my XAML:
<ItemsControl ItemsSource="{Binding Dimensions}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="100" MaxWidth="300" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"
Content="Dimension x"
Target="{Binding ElementName=DimTextBox}" />
<TextBox Grid.Column="1" Name="DimTextBox" >
<Binding Path="/" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<valid:DataSetDimensionValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Where Dimensions is an Observable collection of strings. It seems to bind ok, I get the expected number of labels and textboxes and the textboxes contain the default value. However, when I change something in the textbox, my validation rule doesn’t get called.
I know it is probably something simple but I am stuck. Help?
I’m not sure what the problem actually was but when I updated my Dimensions to be an ObservableCollection of DimensionView where DimensionView is my own class containing a Label and a Value it worked. Code:
I guess maybe it just didn’t like Path=”/”