0

I have created a text box in run time using XAML. I need to make the text box as read only. So I have used a code Browsable[True] & ReadOnly[True] to achieve this. So now the style of the text box is changed. Initially, the data in the text box were in bold. But now it is bit lite not in bold text. Now how to make it as bold. Thanks much.

[DisplayName("Name"), Browsable(true), ReadOnly(true)]  
  • 1
    Do you want to change the color of your `TextBox` (as your Title says) or do you want to make the text in the `TextBox` bold? And can you please provide us more of your code. – Martin Backasch Oct 30 '17 at 10:02
  • There are a couple of related posts for this: one specifically for your question (https://stackoverflow.com/questions/20688408/how-do-you-change-the-text-color-of-a-readonly-textbox) but it uses code behind, and another for a similar question (https://stackoverflow.com/questions/3751990/how-to-change-disabled-background-color-of-textbox-in-wpf) that uses MVVM but relates to the enabled property, but I'm sure you can work out how to relate this to the readonly property – LordWilmore Oct 30 '17 at 11:24

2 Answers2

0

Setting the textBox as readonly does change it´s design and once you have set it as readonly you cant modify it´s content. What about using a Label instead, the user cant modify a Label´s content ever and that´s bascically what you achieve by setting the textBox as readonly.

L. Guthardt
  • 1,990
  • 6
  • 22
  • 44
  • But you have to consider that a user __can not copy__ the Content of a 'Label' by simply selecting the displayed text with the mouse, but he __can copy__ the Text of a read only `TextBox`. – Martin Backasch Oct 30 '17 at 10:15
  • @MartinBackasch Thats true, but OP didnt clarify at all what he really needs and what his purpose is behind that. Would be easier to answer if he would have given us some more information. – L. Guthardt Oct 30 '17 at 10:17
0

Adding the Browsable property to the read only property makes the text box as Read only while generated on run time in WPF.

[Browsable(true), ReadOnly(true)]