Including this question -
When attaching a validation error pattern to my custom text field, for example:
<local:CustomTextBox CustomText="{Binding ViewModelProperty}" Validation.ErrorTemplate="{StaticResource errorTemplate}"/> <ControlTemplate x:Key="errorTemplate"> <DockPanel> <Border BorderBrush="Red" BorderThickness="1"> <AdornedElementPlaceholder x:Name="controlWithError"/> </Border> <TextBlock Foreground="Red" FontSize="20" FontFamily="Segoe UI" Margin="3,0,0,0" MouseDown="Exclamation_MouseDown" Tag="{Binding AdornedElement.(Validation.Errors)[0].ErrorContent, ElementName=controlWithError}">!</TextBlock> </DockPanel> </ControlTemplate>
If a validation error occurs in the ViewModelProperty, my application throws an exception -
Key cannot be null. Parameter name: key
I am not sure why this is happening. Is there something that needs to be done to assign a new error pattern to a custom control?
UPDATE:
I found out that the problem is related to the Tag property in the error pattern. If I remove the tag, it will work fine.
thanks
source share