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

DialogHost PasswordBox PasswordBoxAssist.Password binding is not working, #2930

Closed
ChrisSun112 opened this issue Nov 2, 2022 · 3 comments · Fixed by #2932
Closed

DialogHost PasswordBox PasswordBoxAssist.Password binding is not working, #2930

ChrisSun112 opened this issue Nov 2, 2022 · 3 comments · Fixed by #2932
Assignees
Labels

Comments

@ChrisSun112
Copy link

Bug explanation

I have a PasswordBox,created by DialogHost.Then PasswordBoxAssist.Password binding is not working.
like this:

`  var view = new SampleDialog
        {
            DataContext = new SampleDialogViewModel()
        };

        //show the dialog
        var result = await DialogHost.Show(view, "RootDialog", null, ClosingEventHandler, ClosedEventHandler);`

SampleDialog.xmal
<PasswordBox Grid.Row="1" wpf:HintAssist.HelperText="Name" wpf:HintAssist.Hint="Name" wpf:PasswordBoxAssist.Password="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True}" Style="{StaticResource MaterialDesignFloatingHintPasswordBox}" />

SampleDialogViewModel.cs
`
public class SampleDialogViewModel : ViewModelBase
{

    private string? _name;

    public string? Name
    {
        get => _name;
        set => SetProperty(ref _name, value);
    }

    public string? number;
    public string? Number
    {
        get => number;
        set => SetProperty(ref number, value);
    }
}`

Version

4.6.1

@ChrisSun112 ChrisSun112 added bug evaluation required Items is pending review or evaluation by the team labels Nov 2, 2022
@nicolaihenriksen nicolaihenriksen removed the evaluation required Items is pending review or evaluation by the team label Nov 3, 2022
@nicolaihenriksen nicolaihenriksen self-assigned this Nov 3, 2022
@nicolaihenriksen
Copy link
Contributor

@ChrisSun112 Unfortunately there seems to be a few issues with the PasswordBoxAssist.Password attached property. It works for many cases, but not for others; this being one of the cases where it does not work. I will end up refactoring it...

For now, you can mitigate the issue by simply giving the backing field a non-null value. So, in your sample above, you would change the definition of the backing field in the ViewModel from this:

private string? _name;

to this:

private string? _name = string.Empty;

@Keboo I think I will end up introducing Microsoft.Xaml.Behaviors which is what we initially discussed but I tried to avoid (to have fewer dependencies). I think it is needed in this case, because the current "initialization scheme" for the attached property value does not play nice with the DP precendence list in some scenarios. Using a behavior I believe will mitigate those issues. Are you OK with introducing this dependency?

@Keboo
Copy link
Member

Keboo commented Nov 5, 2022

@nicolaihenriksen yep I am good with it. Will follow up on your PR

@ChrisSun112
Copy link
Author

@nicolaihenriksen Thank you for your advice. It is working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants