我需要测量按钮(和单选按钮)的DesiredSize或ActualHeight/Width,但实际上并没有将它放到可视化树上,但我总是找回无意义的值。测量其他控件(如TextBlock)时,这种方法也适用。UWP XAML中的按钮和单选按钮的DesiredSize
var button = new Button
{
Content = "Hello World",
FontSize = 15
};
button.Measure(new Size(maxWidth, double.PositiveInfinity));
var height = button.DesiredSize.Height;
var width = button.DesiredSize.Width
我回来了21px的高度和0px的宽度。任何想法,为什么我回到宽度为0?
谢谢埃尔维斯!这样可行! –