Branching off of this question -
When attaching a validation error template to my custom textbox like this -
<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 there was a validation error in the ViewModelProperty, my application was throwing an exception -
Key cannot be null.
Parameter name: key
I'm not sure why this is happening. Is there something that needs to be done in order to assign a new error template to a custom control?
UPDATE:
I've figured out that the issue is with the Tag property in the error template. If I remove the Tag, it works just fine.
Thanks