Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JeremyWu917 opened this issue Jun 29, 2020 · 1 comment
Closed
Labels
🏭 enhancement New feature or request

Comments

@JeremyWu917
Copy link
Contributor

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

@NaBian NaBian added the 🏭 enhancement New feature or request label Jul 12, 2020
@NaBian NaBian closed this as completed in 7969435 Jul 12, 2020
@NaBian
Copy link
Member

NaBian commented Jul 12, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏭 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants