Skip to content

Cannot use MVVM type to develop when I use HC control - hc:PasswordBox  #422

Closed

Description

@JeremyWu917

Hi brother,
There is error message that “Passwordbox no longer supports additional attributes built by the blend SDK” when I change control from PasswordBox to HC control - hc:PasswordBox. Is there anyone catch the same issue?
Thx.

Windows10 1809
Microsoft Visual Studio Enterprise 2019 Version 16.6.2
Microsoft .NET Framework Version 4.8.03761
HC Control Version 2.5.0.2

BTH,the screenshot below is the current code.

`public static class PasswordBoxHelper
{
public static readonly DependencyProperty PasswordProperty =
DependencyProperty.RegisterAttached("Password",
typeof(string), typeof(PasswordBoxHelper),
new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged));

    private static void OnPasswordPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        PasswordBox passwordBox = sender as PasswordBox;

        string password = (string)e.NewValue;

        if (passwordBox != null && passwordBox.Password != password)
        {
            passwordBox.Password = password;
        }
    }

    public static string GetPassword(DependencyObject dp)
    {
        return (string)dp.GetValue(PasswordProperty);
    }

    public static void SetPassword(DependencyObject dp, string value)
    {
        dp.SetValue(PasswordProperty, value);
    }
}

public class PasswordBoxBehavior : Behavior<PasswordBox>
{
    protected override void OnAttached()
    {
        base.OnAttached();

        AssociatedObject.PasswordChanged += OnPasswordChanged;
    }

    private static void OnPasswordChanged(object sender, RoutedEventArgs e)
    {
        PasswordBox passwordBox = sender as PasswordBox;

        string password = PasswordBoxHelper.GetPassword(passwordBox);

        if (passwordBox != null && passwordBox.Password != password)
        {
            PasswordBoxHelper.SetPassword(passwordBox, passwordBox.Password);
        }
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();

        AssociatedObject.PasswordChanged -= OnPasswordChanged;
    }
}`

image

Activity

  1. NaBian commented on Jul 12, 2020

    @NaBian
    Member

    now you can set IsSafeEnabled property to false, use binding on UnsafePassword.

  2. added a commit that references this issue on Mar 2, 2025
    7969435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址