WF re-hoster 디자이너 솔루션에 사용되는 WPF PropertyGrid에 대한 암호 (마스크) 필드를 작성하려고합니다. 나는 그것의 보안 요소에 관심이 없다. 나는 그저 비밀 번호가 사용자에게 숨겨 지길 원한다. 내가 정말 구현하지만 결국 정말 도움이 위대한 기사를 찾을 생각은 간단했을 것이다 뭔가 고투 : 기사 당으로 PasswordBoxAssistant 클래스를 생성 한 후WPF PropertyGrid의 암호/마스크 필드가 유지되지 않습니다.
WPF PasswordBox and Data binding
을, 내가 가진 WPF UserControl을 생성 다음 XAML과 코드 :
<Grid>
<PasswordBox x:Name="PasswordBox"
Background="Green"
local:PasswordBoxAssistant.BindPassword="true"
local:PasswordBoxAssistant.BoundPassword="{Binding Password,
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
코드 숨김
XAML :
public partial class PasswordUserControl : UserControl
{
public PasswordUserControl()
{
InitializeComponent();
}
public static readonly DependencyProperty PasswordProperty =
DependencyProperty.Register("Password",
typeof(string), typeof(PasswordUserControl),
new FrameworkPropertyMetadata(PasswordChanged));
public string Password
{
get
{
return (string)GetValue(PasswordProperty);
}
set
{
SetValue(PasswordProperty, value);
}
}
private static void PasswordChanged(DependencyObject source,
DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != null)
{
(source as PasswordUserControl)?.UpdatePassword(e.NewValue.ToString());
}
else
{
(source as PasswordUserControl)?.UpdatePassword(string.Empty);
}
}
private void UpdatePassword(string newText)
{
PasswordBox.Password = Password;
}
}
그때 나는 PropertyValueEditor
클래스 (라고 PasswordEditor.cs)를 생성하고 나는이 작동하지 않는 부분입니다 있으리라 믿고있어 내가 올바르게 설정하고 있지 않다.
저는 UserControl
에서 PropertyValueEditor
의 Value
필드로 PasswordProperty를 바인딩합니다.
public class PasswordEditor : PropertyValueEditor
{
public PasswordEditor()
{
this.InlineEditorTemplate = new DataTemplate();
FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));
FrameworkElementFactory passwordBox = new
FrameworkElementFactory(typeof(PasswordUserControl));
Binding passwordBoxBinding = new Binding("Value") { Mode = BindingMode.TwoWay };
passwordBox.SetValue(PasswordUserControl.PasswordProperty, passwordBoxBinding);
stack.AppendChild(passwordBox);
this.InlineEditorTemplate.VisualTree = stack;
}
}
나는 StringValue
뿐만 아니라 내가 찾은 다른 WF PropertyValueEditor 샘플 당하지만 아무 소용로 설정하려고했습니다.
암호 (마스크 된) 필드가 이제 WPF PropertyGrid에 올바르게 표시되지만 다른 WF 활동으로 전환하고 암호 필드가있는 스위치로 되돌릴 때 값을 유지하지 않습니다.
누구나 올바른 방향으로 나를 가리킬 수 있습니까?
감사합니다.
다시 도움이 될 것입니다.
감사합니다.