WPF: TextBox Read Only and Binding

Say that I have a grid, I click on an object and is displayed on a detail screen. I donโ€™t want the user to edit some data, so I set the TextBox as disabled? Will there be a compulsory job? Basically, I want the TextBox to be gray or disabled? How about this in WPF? Can someone explain?

+6
wpf binding textbox
source share
3 answers

Yes, binding will work with a disabled text field. To disable a text field, you have three options:

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

  • Set IsEnabled to false. This will be grayed out in the text box and will not allow it to receive focus

  • Use a shortcut or text block. This will place the text on the screen without visibility in the editable control.

As for snapping, this will work the same no matter what you do. Set the binding as usual in Xaml or codebehind, and the value will be updated when the backing property changes as usual (assuming you have implemented INotifyPropertyChanged, otherwise it will be set only once)

+20
source share

TextBox has IsReadOnly property, just set it to true

+4
source share

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

+3
source share

All Articles