0

TextBox:

<TextBox Text="{Binding Path=nSetting, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Name="tbSetting" />

Class:

public class FormLink
{
    private string _nSetting;

    public string nSetting 
    { 
        get 
        { 
            return this.validateNumberValue(this._nSetting, 256, 9999, 56);
        } 
        set
        {
            this._nSetting = this.validateNumberValue(value, 256, 9999, 56);
        } 
    }

    private string validateNumberValue(string number, int nMaxReturn, int nMaxParse, int nDefault)
    {
        int pNum = nMaxParse; 
        Int32.TryParse(number, out pNum);

        if (pNum == 0)
        {
            return nDefault.ToString();
        }
        else if (pNum < nMaxReturn)
        {
            return pNum.ToString(); 
        }
        else if (pNum > nMaxReturn)
        {
            return nMaxReturn.ToString();
        }
        else
        {
            return nDefault.ToString();
        }
    }
}  

How do I get this textbox to update properly?

Right now it updates to 256 if number > 256.. BUT... if I keep typing, it doesn't reset to 256. Also, after 10 characters, it resets to 0. I can also start typing 0s and keep going forever with no limit.

How do I get it to always update?
Why does it reset to 0 after the number is 10 characters long?
Why doesn't multiple 0s reset to 56 like I have coded?

1 Answer 1

1

There is a bug in the WPF 4 TextBox (see my question). The solution posted there works.

Sign up to request clarification or add additional context in comments.

2 Comments

Well that makes sense then. What a crappy bug... gotta write a bunch of extra code now... I was wondering why even the basic number logic was failing (last time I checked 000 == 0, etc..). Thanks for the help!
Well that was even easier than I thought.. not much code at all. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.