[ACCEPTED]-WPF: Read only say TextBox and binding-textbox

Accepted answer
Score: 23

Yes, binding will work with a disabled textbox. For 16 disabling the textbox you have three options:

  • Set 15 the IsReadOnly property to true. This will 14 not affect the appearance of the textbox, but 13 will stop the user changing the value inside 12 it.

  • Set IsEnabled to false. This will gray 11 out the textbox and stop it from receiving 10 focus

  • Use a label or a textblock. This will 9 place the text on screen without the appearence 8 of being in an editable control at all.

As 7 for binding, this will work the same no 6 matter what you do. Set up the binding as 5 normal in either the Xaml or codebehind 4 and the value will update when the backing 3 property changes as usual (provided you 2 have implemented INotifyPropertyChanged, otherwise 1 it'll only get set once)

Score: 6

There is a IsReadOnly property on the TextBox, just 1 set it to true

Score: 3

I would use a <TextBlock/> or a <Label/> to 1 display static data instead of a <TextBox/>.

More Related questions