简体   繁体   中英

Extended WPF Toolkit PropertyGrid PasswordEditor

I'm currently developing a WPF application that uses the PropertyGrid out of the Extended WPF Toolkit library.

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. 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.

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. Not even gets the constructor called so I assume there must be some issue with the EditorAttribute declaration.

I'm currently using version 2.4.0 of the Extended WPF Toolkit within a project configured to compile in .NET 4.5.1 .

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. It seems like there was somewhere an error while looking up the Xceed classes and therefore the default editors where used inside the PropertyGrid. So this was not a coding but rather a configuration mistake. Sorry guys for stealing your time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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