我有一个使用MVVM模式实现的WPF应用程序。在这个应用程序中,我试图通过附加属性从PasswordBox获取密码。然而,我得到了上面看到的错误,我不知道我为什么要得到它。我现在拥有的是:
XAML
<PasswordBox x:Name="passwordTextbox" HorizontalAlignment="Left" Height="31" Margin="316,194,0,0" VerticalAlignment="Top" Width="208"
FontSize="16" IsEnabled="{Binding IsEnabled}"
vm:PasswordBoxAttachedProperty.EncryptedPassword="PasswordSecureString, Mode=Twoway, UpdateSourceTrigger=PropertyChanged" />附属性
using System.Security;
using System.Windows;
namespace QMAC.ViewModel
{
public static class PasswordBoxAttachedProperty
{
public static SecureString GetEncryptedPassword(DependencyObject obj)
{
return (SecureString)obj.GetValue(EncryptedPasswordProperty);
}
public static void SetEncryptedPassword(DependencyObject obj, SecureString value)
{
obj.SetValue(EncryptedPasswordProperty, value);
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty EncryptedPasswordProperty =
DependencyProperty.RegisterAttached("EncryptedPassword", typeof(SecureString), typeof(PasswordBoxAttachedProperty));
}
}有什么建议吗?
发布于 2016-04-15 18:17:37
你可能想写
vm:PasswordBoxAttachedProperty.EncryptedPassword=
"{Binding PasswordSecureString, Mode=Twoway, UpdateSourceTrigger=PropertyChanged}"而不是
vm:PasswordBoxAttachedProperty.EncryptedPassword=
"PasswordSecureString, Mode=Twoway, UpdateSourceTrigger=PropertyChanged"https://stackoverflow.com/questions/36654092
复制相似问题