如何将动态创建的文本 block 的高度和宽度设置为自动?
TextBlock myTextBlock = new TextBlock() { Text = "Text Block", Width = 140, Height = 40, FontSize = 20 };
最佳答案
将宽度(或高度)设置为 Double.NaN
等同于在 XAML 中将宽度设置为 auto
。
TextBlock myTextBlock = new TextBlock() { Text = "Text Block", Width = Double.NaN, Height = Double.NaN, FontSize = 20 };
另见 MSDN
关于c# - 使文本 block 的宽度自动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23084353/