views:

741

answers:

3

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

+1  A: 

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

Thomas Levesque
+1  A: 

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

Bob King
+4  A: 

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)

Martin Harris