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 7088319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:47:10+00:00 2026-05-28T07:47:10+00:00

I have always admired the way Josh Smith has built his sample application .

  • 0

I have always admired the way Josh Smith has built his sample application.
And I have also tried to emulate the way in which the ViewModels of his application implements the IDataErrorInfo property and through a custom DataTemplate renders the errors before the user.
Here is the data template that he uses to show the error:

<DataTemplate DataType="{x:Type ValidationError}">
  <TextBlock FontSize="10"
             FontStyle="Italic"
             Foreground="Red"
             HorizontalAlignment="Right"
             Margin="0,1"
             Text="{Binding Path=ErrorContent}"/>
</DataTemplate>

A working sample of this data template getting consumed is as follows:

<TextBox x:Name="txtUsername"
         Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2"
         Width="300"
         Margin="2" 
         Text="{Binding Path=Username,
             ValidatesOnDataErrors=True,
             UpdateSourceTrigger=PropertyChanged}"
         Validation.ErrorTemplate="{x:Null}"/>

<ContentPresenter Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" 
                  Content="{Binding ElementName=txtUsername,
                      Path=(Validation.Errors).CurrentItem}"/>

The default ErrorTemplate of the textbox (a red boundary that appears around it) is replaced by a new error template in which a content presenter placed just below the text box will convey the error to the user — certainly a superior and more elegant template.

If you have read the above code, you might well have guessed that I am trying to create a login form.

Unfortunately, login forms demand password (and subsequently PasswordBox). PasswordBox does not provide "Password" as dependency property. I did not want to break the MVVM guideline of trying to avoid code behind as much as possible and so was tempted to go for the PasswordBoxAssistant class mentioned here.
This otherwise is a nice solution, save one thing. It is not letting me validate the Password Box with Josh’s data template.
I have validated the password property of my ViewModel for not being empty. The property is getting validated as my "Login" button is not getting enabled without the user filling in password. But the "Enter password" message that I did set as a part of this property validation is not being rendered by the Content presenter that lies below the PasswordBox. Here goes the code:

<Label Content="Password:" Grid.Column="0" Grid.Row="2" Margin="2" />

<PasswordBox x:Name="PasswordBox"
             Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"
             Margin="2"
             Validation.ErrorTemplate="{x:Null}" 
             ff:PasswordBoxAssistant.BindPassword="true"  
             ff:PasswordBoxAssistant.BoundPassword="{Binding Path=Password,
                 Mode=TwoWay,
                 UpdateSourceTrigger=PropertyChanged}"/>

<ContentPresenter Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2"
                  Content="{Binding ElementName=PasswordBox,
                  Path=(Validation.Errors).CurrentItem}"/>

Needless to say that the ff in the above code stands for the namespace reference:

xmlns:ff="clr-namespace:MyProject.UserViews"

I am sure, this problem is happening because the Password property has got extended by the helper class. If I drop this approach, I will have to remove the Password property from the IDataErrorInfo Implementation and on Login button click will have to verify it, presenting the user with a message box. But not without compromising consistency. I am not much aware of Dependency Properties; can there be any workaround? Will altering the helper class in some way let me have the red error message back in place?

  • 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-05-28T07:47:11+00:00Added an answer on May 28, 2026 at 7:47 am

    I don’t see ValidatesOnDataErrors=True in your Password binding, so perhaps that is your problem. By default, that is set to False which means the binding won’t alert the UI of any validation errors.


    That said, I think the Password is intentionally not a DependencyProperty because you really shouldn’t be storing passwords as plain text.

    Usually I end up passing the PasswordBox.Password (or the entire PasswordBox) as a CommandParameter to my LoginCommand, then it can take the data and do whatever it wants to it. Usually this means hashing it or something and comparing it with the stored password’s hash to see if its the same. If the login fails, I write the associated error message to a property in my ViewModel, which is bound to the login UI.

    <Button Command="{Binding LoginCommand}" 
            CommandParameter="{Binding ElementName=MyPasswordBox, Path=Password}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have always been challenged by the way lists work and am confused about
I have always used: serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); which means that I will accept connections
I have always used Visual Studios built in GUI support for configuring my projects,
I have always wondered what the most effective way is of creating String's in
I have always thought that the .equals() method in java should be overridden to
I have always used || (two pipes) in OR expressions, both in C# and
I have always wondered how people update a previous line in a command line.
I have always made a point of writing nice code comments for classes and
I have always been for documenting code, but when it comes to AJAX +
I have always wondered WHaT tHE HecK?!? is the difference between JScript and JavaScript.

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.