【发布时间】:2014-01-29 13:31:35
【问题描述】:
我有一个基本问题。我有这样的 MainPage.xaml 代码,
<!--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()); }
标签: c# wpf visual-studio-2012 windows-8 windows-phone-8