1

Closed

Default TextUnMasked behaviour

description

(Sorry for the duplicate post. I'm new here, not sure where it should go.)
 
Hi, great tool you got here!
 
Just one comment. I notice that TextUnMasked does not always update as expected.
 
For example, in MaskedEditDemo.MainPage.xaml, when you change the code from:
 
    private void MaskCus_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
    {
        LblCusUnMask.Text = this.MaskCus.TextUnMasked;
    }
 
to:
 
    static int i = 0;
    private void MaskCus_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
    {
        if (++i % 2 == 0)
        {
            LblCusUnMask.Text = this.MaskCus.TextUnMasked;
        }
    }
 
then the previous value is not always correct. I see that there is a property "UnMaskedAtLostfocus" that fix this when the focus is lost, but should you not rather always set TextUnMasked as the default behaviour on text changed? I think this would make more sense from a user's point of view.
 
Regards
Closed Dec 16, 2009 at 9:22 PM by FCerqueira
Property TextUnmasked not designed for use in the event text_changed. The TextChanged event is used internally and this causes confusion in the call Unmasked if used together.

comments

boneless_skeletal wrote Nov 20, 2009 at 12:47 PM

Here is a quick fix for my situation:
    private void MaskEdit_TextChanged(object sender, TextChangedEventArgs e)
    {
        try
        {
            // ...
        }
        finally
        {
            var dummy = TextUnMasked;
        }
    }
The only problem with setting TextUnMasked on text-changed is that it will not have a default value if Text had a value before the control was loaded.

Let me know what you think.

boneless_skeletal wrote Nov 24, 2009 at 10:50 AM

MaskedEdit.cs:
    public string TextUnMasked
    {
        get
        {
            SetValue(TextUnMaskedProperty, UnMaskText());   // ***
            return (string)GetValue(TextUnMaskedProperty);
        }
        private set { SetValue(TextUnMaskedProperty, value); }
    }
*** The rule is that you are not allowed to add custom code within the getter/setter of the DependencyProperty. The problem is that these changes will not reflect on UI bindings. Rather used events, as specified in the PropertyMetadata(...) argument.

THUS, the two places where TextUnMasked needs to be updated is:
1) See my previous comment/post.
2) Right after the line "base.TextChanged += new TextChangedEventHandler(MaskEdit_TextChanged);" inside "MaskEdit_Loaded".

Oh, and I love your control! Great job.

FCerqueira wrote Dec 16, 2009 at 9:21 PM

Thanks!

Property TextUnmasked not designed for use in the event text_changed. The TextChanged event is used internally and this causes confusion in the call Unmasked if used together.

wrote Dec 16, 2009 at 9:22 PM

wrote Feb 13, 2013 at 10:42 PM

wrote May 16, 2013 at 1:20 AM