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?

PiZzL3
  • 2,092
  • 4
  • 22
  • 30

1 Answers1

1

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

Community
  • 1
  • 1
Daniel Rose
  • 17,233
  • 9
  • 65
  • 88
  • 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! – PiZzL3 Apr 03 '11 at 18:20
  • Well that was even easier than I thought.. not much code at all. Thanks again! – PiZzL3 Apr 03 '11 at 19:45