首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于"SecureString“的SecureString不支持转换字符串

用于"SecureString“的SecureString不支持转换字符串
EN

Stack Overflow用户
提问于 2016-04-15 18:09:50
回答 1查看 1.1K关注 0票数 0

我有一个使用MVVM模式实现的WPF应用程序。在这个应用程序中,我试图通过附加属性从PasswordBox获取密码。然而,我得到了上面看到的错误,我不知道我为什么要得到它。我现在拥有的是:

XAML

代码语言:javascript
复制
<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" />

附属性

代码语言:javascript
复制
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));
    }
}

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-15 18:17:37

你可能想写

代码语言:javascript
复制
vm:PasswordBoxAttachedProperty.EncryptedPassword=
    "{Binding PasswordSecureString, Mode=Twoway, UpdateSourceTrigger=PropertyChanged}"

而不是

代码语言:javascript
复制
vm:PasswordBoxAttachedProperty.EncryptedPassword=
    "PasswordSecureString, Mode=Twoway, UpdateSourceTrigger=PropertyChanged"
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36654092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档