I would like to have a xamMaskedEditor that only displays part of the text when not being edited. If the user is allowed entry into the field, then they can see the full value. For example, if I have social security # 123-45-6789, I want the editor to display ***-**-6789 when not being edited. Same goes for a credit card #. Is there a way of doing this? I probably have to use a value converter, but how does the value converter know the user is currently editing that field?
Thanks,
Joe
Hi Joe,
The following ValueConverter will display the SSN with * chars replacing the first 5 numbers when IsInEditMode is false.
class SecureSSNConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string str = value as string; if (null != str && Regex.Match(str, @"^\d{3}-\d{2}-\d{4}$").Success) { string replacedStr = Regex.Replace(str, @"^\d{3}-\d{2}", "***-**"); return replacedStr; } return value; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value; }}
Assign an instance of this converter to the XamMaskedEditor's ValueToDisplayTextConverter property.
mySSNMaskedEditor.ValueToDisplayTextConverter = new SecureSSNConverter();
Note that ValueToDisplayTextConverter only gets called when the editor is not in edit mode.
Thank you for the help, that is exacally what I am looking for.