Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
275
Partially hiding text when not in edit mode.
posted

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

  • 9694
    Verified Answer
    posted

    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.

  • 9694
    posted

    Hi Joe,

    I've been looking into this issue and have not found a solution yet. I'm hoping we can accomplish this by applying a ValueConverter to a xamEditor. Obviously, this functionality would be very useful.