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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:39:38+00:00 2026-05-22T02:39:38+00:00

I have 2 PasswordBoxes. I need to check are passwords equal. I don’t want

  • 0

I have 2 PasswordBoxes. I need to check are passwords equal. I don’t want to write this condition into [].xaml.cs code, but i want to mark PasswordBox in red when passwords aren’t equal.

Should i write special ValidationRule, some code in ViewModel or something else? Can anyone help me? Now the validation is written in the [].xaml.cs but i want to avoid it.

  • 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-22T02:39:39+00:00Added an answer on May 22, 2026 at 2:39 am

    Using:

    <PasswordBox Name="tbPassword" />
    <PasswordBox Name="tbPasswordConf" />
    <PasswordValidator 
          Box1="{Binding ElementName=tbPassword}" 
          Box2="{Binding ElementName=tbPasswordConf}" />
    

    Code (this code is not cover all cases):

    public class PasswordValidator : FrameworkElement
     {
      static IDictionary<PasswordBox, Brush> _passwordBoxes = new Dictionary<PasswordBox, Brush>();
    
      public static readonly DependencyProperty Box1Property = DependencyProperty.Register("Box1", typeof(PasswordBox), typeof(PasswordValidator), new PropertyMetadata(Box1Changed));
      public static readonly DependencyProperty Box2Property = DependencyProperty.Register("Box2", typeof(PasswordBox), typeof(PasswordValidator), new PropertyMetadata(Box2Changed));
    
      public PasswordBox Box1
      {
       get { return (PasswordBox)GetValue(Box1Property); }
       set { SetValue(Box1Property, value); }
      }
      public PasswordBox Box2
      {
       get { return (PasswordBox)GetValue(Box2Property); }
       set { SetValue(Box2Property, value); }
      }
    
      private static void Box1Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
      }
      private static void Box2Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
       var pv = (PasswordValidator)d;
       _passwordBoxes[pv.Box2] = pv.Box2.BorderBrush;
       pv.Box2.LostFocus += (obj, evt) =>
       {
        if (pv.Box1.Password != pv.Box2.Password)
        {
         pv.Box2.BorderBrush = new SolidColorBrush(Colors.Red);
        }
        else
        {
         pv.Box2.BorderBrush = _passwordBoxes[pv.Box2];
        }
       };
      }
     }
    

    Also, it’s possible to define dependency property with style of error and setting it instead of BorderBrush. But i don’t know how to use in this case the standard ErrorTemplate.

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

Sidebar

Related Questions

How can I do this in XAML: PSEUDO-CODE: <TextBox Text={Binding Password} Type=Password/> so that
I am not sure why this code doesn't work I have follow according to
have a php code like this,going to convert it in to C#. function isValid($n){
I have a PasswordBox and I need to use this control even as a
Have a look at this piece of C++ code: class Foo { int a;
I have a DataGridTemplateColumn with DataTemplate as a PasswordBox. I want to warn user
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have a painfully simple blog Post creator, and I'm trying to check if the
I have the need to calculate the size of a file I am encrypting

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.