Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:50:15+00:00 2026-06-18T03:50:15+00:00

Branching off of this question – When attaching a validation error template to my

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:50:16+00:00Added an answer on June 18, 2026 at 3:50 am

    Alright so the way I managed to fix the issue was by removing the AdornedElement keyword and changing the error template as follows:

    <local:CustomTextBox CustomText="{Binding ViewModelProperty}">
        <Validation.ErrorTemplate>
            <ControlTemplate>
                <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">!</TextBlock>
                </DockPanel>
            </ControlTemplate>
        </Validation.ErrorTemplate>
        <local:CustomTextBox.Style>
            <Style TargetType="{x:Type local:CustomTextBox}">
                <Style.Triggers>
                    <Trigger Property="Validation.HasError" Value="true">
                        <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                        <Setter Property="Tag" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </local:CustomTextBox.Style>
    </local:CustomTextBox>
    

    What I don’t understand is why it behaves differently when using the AdornedElement keyword but works fine when binding the Tag/Tooltip using the RelativeSource. While the problem is solved, I would welcome any ideas as to why this happened.

    Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Branching off of questions like this one , I'm looking to wrap jQuery's $.ajax()
NOTE: This question is inspired by the git-svn branching question and NOT a duplicate!
All examples of svn branching I have seen so far look like this svn
Branching off from this link it seems that Request.ServerVariables(SCRIPT_NAME) doesn't return anything. I've just
At work we use a branching strategy where all changes start off in a
I am using http://nvie.com/posts/a-successful-git-branching-model/ As far as I understand, main repo in this model
I'm new to Git and this is really confusing. I wanted to start off
I need to use some features of SVN like branching, history, reverting, revisions for
I've got a question regarding git branching protocol. I'm starting to get more familiar
I have multiple pages branching of a title page, and when a back button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.