Reputation: 89
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
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