"SecureString" 的 TypeConverter 不支持转换字符串
TypeConverter for "SecureString" does not support converting a string
我有一个正在使用 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));
}
}
有什么建议吗?
你可能想写
vm:PasswordBoxAttachedProperty.EncryptedPassword=
"{Binding PasswordSecureString, Mode=Twoway, UpdateSourceTrigger=PropertyChanged}"
而不是
vm:PasswordBoxAttachedProperty.EncryptedPassword=
"PasswordSecureString, Mode=Twoway, UpdateSourceTrigger=PropertyChanged"
我有一个正在使用 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));
}
}
有什么建议吗?
你可能想写
vm:PasswordBoxAttachedProperty.EncryptedPassword=
"{Binding PasswordSecureString, Mode=Twoway, UpdateSourceTrigger=PropertyChanged}"
而不是
vm:PasswordBoxAttachedProperty.EncryptedPassword=
"PasswordSecureString, Mode=Twoway, UpdateSourceTrigger=PropertyChanged"