WPF TextBox value doesn't change on OnPropertyChanged

Posted by jpsstavares on Stack Overflow See other posts from Stack Overflow or by jpsstavares
Published on 2010-06-16T17:47:32Z Indexed on 2010/06/16 17:52 UTC
Read the original article Hit count: 177

Filed under:
|
|
|

I have a TextBox whose Value is binded to a ViewModel property:

        <TextBox Name="txtRunAfter" Grid.Column="4" Text="{Binding Mode=TwoWay, Path=RunAfter}" Style="{StaticResource TestStepTextBox}"/>

The set and get were working fine until I tried to add some validation when the Value is set:

    private int _runAfter = 0;
    public string RunAfter
    {
        get
        {
            return _runAfter.ToString();
        }

        set
        {
            int val = int.Parse(value);

            if (_runAfter != val)
            {
                if (val < _order)
                    _runAfter = val;
                else
                {
                    _runAfter = 0;
                    OnPropertyChanged("RunAfter");
                }
            }
        }
    }

Although the OnPropertyChanged is reached (I have dubugged that), the View is not changed. How can I make this work?

Thanks, José Tavares

© Stack Overflow or respective owner

Related posts about wpf

Related posts about mvvm