You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DialogHost PasswordBox PasswordBoxAssist.Password binding is not working, #2930
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);`
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);
}
}`
@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:
privatestring?_name;
to this:
privatestring?_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?
Activity
nicolaihenriksen commentedon Nov 4, 2022
@ChrisSun112 Unfortunately there seems to be a few issues with the
PasswordBoxAssist.Passwordattached 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:
to this:
@Keboo I think I will end up introducing
Microsoft.Xaml.Behaviorswhich 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 commentedon Nov 5, 2022
@nicolaihenriksen yep I am good with it. Will follow up on your PR
ChrisSun112 commentedon Nov 7, 2022
@nicolaihenriksen Thank you for your advice. It is working now.