使文本块的宽度自动化

Mih*_*hir 6 c# xaml windows-phone-8

如何将动态创建的文本块的高度和宽度设置为自动?

TextBlock myTextBlock = new TextBlock() { Text = "Text Block", Width = 140, Height = 40, FontSize = 20 };
Run Code Online (Sandbox Code Playgroud)

Cla*_*sen 6

将宽度(或高度)设置Double.NaN为相当于将宽度设置为autoXAML.

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

另请参阅MSDN