[英]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.