gpt4 book ai didi

c# - 用于 “SecureString”的TypeConverter不支持转换字符串

转载 作者:行者123 更新时间:2023-12-03 10:57:51 24 4
gpt4 key购买 nike

我有一个正在使用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"

关于c# - 用于 “SecureString”的TypeConverter不支持转换字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36654092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com