Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Read only say TextBox and binding

Say I have a grid, I click an object and it displays in a detail screen. I don't want the user to edit some data so I set the TextBox as disabled? Will binding work? Basically what I want is the TextBox to be greyed out or disabled? How about it in WPF? Can someone explain?

like image 789
abmv Avatar asked Jun 18 '09 13:06

abmv


1 Answers

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

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

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

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

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

like image 117
Martin Harris Avatar answered Sep 30 '22 15:09

Martin Harris