我有这段XAML代码:
<Window x:Class="SizingTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Label x:Name="theLabel" Width="Auto">A very large label with a lot of text</Label>
</Grid>
</Window>
在代码后台,我试图获取标签的实际宽度,我认为
theLabel.ActualWidth
这个代码可以解决问题,但是在尝试了这段代码后:
public Window1()
{
InitializeComponent();
double width = theLabel.ActualWidth;
}
宽度的值为0,我也通过theLabel.Width进行了检查,返回NaN,theLabel.DesiredSize.Width也返回0。我该使用什么方法来找到标签的真实宽度?
谢谢。