简体   繁体   English

扩展的WPF工具包PropertyGrid PasswordEditor

[英]Extended WPF Toolkit PropertyGrid PasswordEditor

I'm currently developing a WPF application that uses the PropertyGrid out of the Extended WPF Toolkit library. 我目前正在开发一个WPF应用程序,该应用程序使用Extended WPF Toolkit库中的PropertyGrid。

To display names and descriptions in a language independent manor I'm using a wrapper class that contains the required attributes according the provided documentation. 为了使用独立于语言的庄园显示名称和描述,我使用了包装类,该包装类包含根据提供的文档提供的必需属性。 Here a shortened listing 这是缩短的清单

[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
}

Now I would like to use a custom editor for the LdapPassword property since it is a password and should not be visible as plain text in the PropertyGrid. 现在,我想对LdapPassword属性使用自定义编辑器,因为它是密码,并且在PropertyGrid中不应以纯文本形式显示。 As I'm not the only and not the first one to come up with this requirement I found an implementation of such an editor in the discussions section of the project on Codeplex. 因为我不是唯一提出此要求的人,也不是第一个提出此要求的人,所以我在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;
        }
    }
}

Accordingly to the documentation provided on Codeplex all one needs to do is to add the EditorAttribute on the property and all should be fine but the PasswordEditor is not shown at all. 根据Codeplex上提供的文档,所有需要做的就是在属性上添加EditorAttribute,并且都应该可以,但是根本不显示PasswordEditor。 Not even gets the constructor called so I assume there must be some issue with the EditorAttribute declaration. 甚至没有调用构造函数,因此我认为EditorAttribute声明一定存在问题。

I'm currently using version 2.4.0 of the Extended WPF Toolkit within a project configured to compile in .NET 4.5.1 . 我目前在配置为在.NET 4.5.1中进行编译的项目中使用Extended WPF Toolkit的2.4.0版本。

Someone with an idea what could be wrong? 有人知道什么地方可能出问题了?

Just found the solution myself. 我自己找到了解决方案。 The WPF application includes a plugin architecture which loads all classes and their dependencies at runtime. WPF应用程序包括一个插件体系结构,该体系结构在运行时加载所有类及其依赖项。 It seems like there was somewhere an error while looking up the Xceed classes and therefore the default editors where used inside the PropertyGrid. 查找Xceed类时似乎出现了错误,因此在PropertyGrid中使用了默认编辑器。 So this was not a coding but rather a configuration mistake. 因此,这不是编码,而是配置错误。 Sorry guys for stealing your time. 抱歉,您正在浪费时间。

暂无
暂无

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

相关问题 WPF扩展工具包PropertyGrid-组成SelectedObject - WPF Extended Toolkit PropertyGrid - Compose SelectedObject 具有自定义属性的扩展WPF工具包PropertyGrid - Extended WPF Toolkit PropertyGrid with Custom Attributes 扩展的WPF工具包PropertyGrid IsExpandable模板 - Extended WPF Toolkit PropertyGrid IsExpandable Template 将ViewModel直接绑定到扩展WPF工具包PropertyGrid - Binding a ViewModel directly to an Extended WPF Toolkit PropertyGrid PropertyGrid(扩展WPF工具包)中没有xaml的多行字符串? - Multi-line string in PropertyGrid (Extended WPF toolkit) without xaml? WPF 扩展工具包 PropertyGrid - 默认展开所有属性 - WPF Extended Toolkit PropertyGrid - Expand all properties by default WPF扩展工具包PropertyGrid DateTime属性更新问题 - WPF extended toolkit PropertyGrid DateTime property updating issue 如何使用 C# 中的另一个(嵌套)编辑器为扩展 WPF 工具包 PropertyGrid 创建自定义属性编辑器? - How to create a custom property editor for Extended WPF Toolkit PropertyGrid with another (nested) editor in C#? 在使用PropertyGrid的CollectionEditor(扩展的WPF工具包)时,如何填充出现的CollectionControlDialog? - How to populate the CollectionControlDialog that comes up when using the PropertyGrid's CollectionEditor (Extended WPF Toolkit)? 如何在扩展工具包PropertyGrid中更改背景/前景 - How to change background/Foreground in an Extended Toolkit PropertyGrid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM