我有一個基本問題。我有我的MainPage.xaml中這樣的代碼,WP8在運行時得到網格(內容面板)高度
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"
Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Foreground="Black" />
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" >
</Grid>
</Grid>
在我MainPage.xaml.cs中的文件,
public MainPage()
{
InitializeComponent();
MessageBox.Show(ContentPanel.Height.ToString());
}
我的消息框返回NaN
的價值,但我想獲得一個特定的值,而不是無限期的價值。
謝謝。
使用void MainWindow_Loaded(object sender,RoutedEventArgs e) MessageBox.Show(ContentPanel.ActualHeight.ToString()); } –