none
Binding settings and changing the value in code-behind file. RRS feed

  • Question

  • I have bound a TextBox with its property Text to a user setting. It works fine. (the Text is auto saving to the setting file if changes make to the Text in the UI)

    Until I change the Text value at the code-behind file like this:

    txt.Text = "some stirngs";
    it is not working. (The Text is not auto saving to the Setting file anymore.)

    is there any other codes I should add to solve this problems?

    thanks.

    Tuesday, July 5, 2011 10:44 AM

Answers

  • Problem solved!

    Because the defalut binding trigger of the TextBox is "LostFocus". If setting the value manullly, it won't never trigger the "LostFocus". That is the problem.

    then, simply changing the trigger to "PropertyChanged" like below:

    UpdateSourceTrigger=PropertyChanged

    and it will work properly.

     

     

    You are not answering the quesiotn right.

    But, thanks for your clue.

    • Marked as answer by Jia-Yu Li Tuesday, July 5, 2011 11:34 AM
    Tuesday, July 5, 2011 11:33 AM

All replies

  • Hey, Jia. I hope you're fine.

    This case is a known issue, dear mate. Setting a value manually to the textBox will stop or even clear the Binding from working. I guess recreating the binding from the code or even updating it if it still exists will do the trick.

    I hope this helps or at least gives you a hint on how things may go. Please, mark my reply as "Answer" if it helped.


    Ahmed M. Gamil
    • Proposed as answer by Gamil Silvergeek Tuesday, July 5, 2011 11:03 AM
    • Unproposed as answer by Jia-Yu Li Tuesday, July 5, 2011 11:34 AM
    Tuesday, July 5, 2011 11:03 AM
  • Problem solved!

    Because the defalut binding trigger of the TextBox is "LostFocus". If setting the value manullly, it won't never trigger the "LostFocus". That is the problem.

    then, simply changing the trigger to "PropertyChanged" like below:

    UpdateSourceTrigger=PropertyChanged

    and it will work properly.

     

     

    You are not answering the quesiotn right.

    But, thanks for your clue.

    • Marked as answer by Jia-Yu Li Tuesday, July 5, 2011 11:34 AM
    Tuesday, July 5, 2011 11:33 AM
  • You're welcome, dear friend. :)
    Ahmed M. Gamil
    Tuesday, July 5, 2011 11:57 AM