Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 };
like image 810
Mihir Avatar asked Apr 15 '14 12:04

Mihir


1 Answers

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

like image 183
Claus Jørgensen Avatar answered Nov 02 '22 20:11

Claus Jørgensen