繁体   English   中英

扩展的WPF工具包PropertyGrid PasswordEditor

[英]Extended WPF Toolkit PropertyGrid PasswordEditor

我目前正在开发一个WPF应用程序,该应用程序使用Extended WPF Toolkit库中的PropertyGrid。

为了使用独立于语言的庄园显示名称和描述,我使用了包装类,该包装类包含根据提供的文档提供的必需属性。 这是缩短的清单

[LocalizedDisplayName("ServerConfig", typeof(Resources.Strings.Resources))]
public class ServerConfigPropertyGrid
{
    #region fields
    private ServerConfig serverConfig;
    #endregion

    #region properties
    [LocalizedCategory("VeinStoreCategory", typeof(Resources.Strings.Resources))]
    [LocalizedDisplayName("ActiveDirectoryPasswordDisplayName", typeof(Resources.Strings.Resources))]
    [LocalizedDescription("ActiveDirectoryPasswordDescription", typeof(Resources.Strings.Resources))]
    [Editor(typeof(PasswordEditor), typeof(PasswordEditor))]
    public string LdapPassword
    {
        get { return serverConfig.LdapPassword; }
        set { serverConfig.LdapPassword = value; }
    }
    #endregion

    #region constructor
    public ServerConfigPropertyGrid(ServerConfig serverConfig)
    {
        // store serverConfig
        this.serverConfig = serverConfig;
    }
    #endregion
}

现在,我想对LdapPassword属性使用自定义编辑器,因为它是密码,并且在PropertyGrid中不应以纯文本形式显示。 因为我不是唯一提出此要求的人,也不是第一个提出此要求的人,所以我在Codeplex项目的讨论部分找到了这种编辑器的实现。

public class PasswordEditor : ITypeEditor
{
    #region fields
    PropertyItem _propertyItem;
    PasswordBox _passwordBox; 
    #endregion

    public FrameworkElement ResolveEditor(PropertyItem propertyItem)
    {
        _propertyItem = propertyItem;

        _passwordBox = new PasswordBox();
        _passwordBox.Password = (string)propertyItem.Value;
        _passwordBox.LostFocus += OnLostFocus;

        return _passwordBox;
    }

    private void OnLostFocus(object sender, RoutedEventArgs e)
    {
        // prevent event from bubbeling
        e.Handled = true;

        if (!_passwordBox.Password.Equals((string)_propertyItem.Value))
        {
            _propertyItem.Value = _passwordBox.Password;
        }
    }
}

根据Codeplex上提供的文档,所有需要做的就是在属性上添加EditorAttribute,并且都应该可以,但是根本不显示PasswordEditor。 甚至没有调用构造函数,因此我认为EditorAttribute声明一定存在问题。

我目前在配置为在.NET 4.5.1中进行编译的项目中使用Extended WPF Toolkit的2.4.0版本。

有人知道什么地方可能出问题了?

我自己找到了解决方案。 WPF应用程序包括一个插件体系结构,该体系结构在运行时加载所有类及其依赖项。 查找Xceed类时似乎出现了错误,因此在PropertyGrid中使用了默认编辑器。 因此,这不是编码,而是配置错误。 抱歉,您正在浪费时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM