How to stop a WPF binding from ignoring the PropertyChanged event that it caused?

Posted by Jacob Stanley on Stack Overflow See other posts from Stack Overflow or by Jacob Stanley
Published on 2009-05-01T03:36:05Z Indexed on 2010/04/26 1:43 UTC
Read the original article Hit count: 377

Filed under:
|

I have a TextBox bound to a ViewModel's Text property with the following setup:

Xaml

<TextBox Text="{Binding Text}"/>

C#

public class ViewModel : INotifyPropertyChanged
{
    public string Text
    {
        get
        {
            return m_Text;
        }
        set
        {
            if (String.Equals(m_Text, value))
            {
                return;
            }

            m_Text = value.ToLower();
            RaisePropertyChanged("Text");
        }
    }

    // Snip
}

When I type some stuff in to the TextBox it successfully sets the Text property on the ViewModel. The problem is that WPF ignores the property changed event that is raised by it's own update. This results in the user not seeing the text they typed converted to lowercase.

How can I change this behaviour so that the TextBox updates with lowercase text?

Note: this is just an example I have used to illustrate the problem of WPF ignoring events. I'm not really interested in converting strings to lowercase or any issues with String.Equals(string, string).

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding