Set the Text property of a TextBox
-
Ok, I shall try to explain as thoroughly as possible the problem I'm experiencing. I have TextBox in a tab on the left of my window (Text1). The rest of the window has another TextBox (Text2). As I type into Text2, if I press F12, I grab the current word and try to put it into Text property on the TextBox Text1. Although the TextChanged event fires and I can see its Text property has been set, visually it isn't set and the code dependant on the new value runs and then 'unruns' if you follow me. I don't know if this is a focus issue or something, but there are no exceptions in the output window and no more major breakages. Does anyone have any idea what I might be missing here? Thanks in advance, Simon
-
Ok, I shall try to explain as thoroughly as possible the problem I'm experiencing. I have TextBox in a tab on the left of my window (Text1). The rest of the window has another TextBox (Text2). As I type into Text2, if I press F12, I grab the current word and try to put it into Text property on the TextBox Text1. Although the TextChanged event fires and I can see its Text property has been set, visually it isn't set and the code dependant on the new value runs and then 'unruns' if you follow me. I don't know if this is a focus issue or something, but there are no exceptions in the output window and no more major breakages. Does anyone have any idea what I might be missing here? Thanks in advance, Simon
This is a WPF project ? Do you have any events on the other textbox that might fire and change or reject the text ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
This is a WPF project ? Do you have any events on the other textbox that might fire and change or reject the text ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Yeah, this is WPF. I know what you mean, but I don't set the Text property anywhere else or set e.Handled to true or false anywhere. When I set the Text property, TextChanged fires on that TextBox as normal. In that handler, I read the value out to use it for other purposes. All this code does run ok, but visually, it's as if nothing happened! This is odd. I'm going to try and create a simple WPF app with 2 TextBoxes and do something similar. If you have any other ideas, I'd love to hear them. :)
-
Ok, I shall try to explain as thoroughly as possible the problem I'm experiencing. I have TextBox in a tab on the left of my window (Text1). The rest of the window has another TextBox (Text2). As I type into Text2, if I press F12, I grab the current word and try to put it into Text property on the TextBox Text1. Although the TextChanged event fires and I can see its Text property has been set, visually it isn't set and the code dependant on the new value runs and then 'unruns' if you follow me. I don't know if this is a focus issue or something, but there are no exceptions in the output window and no more major breakages. Does anyone have any idea what I might be missing here? Thanks in advance, Simon
Are you setting the text property of TextBox1, or are you updating property to which the Text property of TextBox1 is bound? If you are updating a property the problem is likely that you need to raise an OnPropertyChanged event for that property. You'll have to implement INotifyPropertyChange...
-
Are you setting the text property of TextBox1, or are you updating property to which the Text property of TextBox1 is bound? If you are updating a property the problem is likely that you need to raise an OnPropertyChanged event for that property. You'll have to implement INotifyPropertyChange...
Hi, I am using binding a fair bit, but in this particular case, this textbox is not bound to anything. I am merely doing the following: myTextBox.Text = "some text"; I am getting some bizarre feeling that WPF is preventing the visual change based on some form of focus or caret permission type thing, but I can't be convinced of this. It's an odd one at the moment.