How to resize textbox upon inserting text programmatically in WPF application?

I am kinda new to WPF. I am programatically inserting text into textbox. This textbox is added to stackpanel programatically.

The problem is the textbox is not resizing. I have set textbox textwrapping to wrap.

textbox.TextWrapping=TextWrapping.Wrap;

Please guide me, how to set the text box resize after assigning text to it.

textbox.Text="some long paragraph text";

Upvotes: 0

Views: 135

Answers (2)

after bit struggle, finally I figured out the solution.

In my case, by saying resize I mean, the textbox should expand according to the text content. But in my code, I had set the height of the text box. Thats why after assigning a paragraph of text, it was not resizing (expanding according to the text content)

If you set height of the text box, then it wont expand. Set margin if required and set textwrapping to wrap. It will work fine now.

Upvotes: 0

Engr Inzamam ul Haq
Engr Inzamam ul Haq

Reputation: 1

Increase the width of textbox or define MaxWidth and use this TextWrapping Property. It May help You.

Upvotes: 0

Related Questions