Mihir
Mihir

Reputation: 89

Make width auto of text block

How to set height and widhth of dynamically created text block to auto?

TextBlock myTextBlock = new TextBlock() { Text = "Text Block", Width = 140, Height = 40, FontSize = 20 };

Upvotes: 3

Views: 2634

Answers (1)

Claus Jørgensen
Claus Jørgensen

Reputation: 26351

Setting width (or height) to Double.NaN is the equivalent of setting the width to auto in XAML.

TextBlock myTextBlock = new TextBlock() { Text = "Text Block", Width = Double.NaN, Height = Double.NaN, FontSize = 20 };

Also see MSDN

Upvotes: 7

Related Questions