Wpf control size to content?

Shimmy Weitzhandler picture Shimmy Weitzhandler · Nov 17, 2009 · Viewed 108.5k times · Source

How do I make a WPF control to change its size according the content in it?

Answer

Reed Copsey picture Reed Copsey · Nov 17, 2009

For most controls, you set its height and width to Auto in the XAML, and it will size to fit its content.

In code, you set the width/height to double.NaN. For details, see FrameworkElement.Width, particularly the "remarks" section.