私が正しく理解していれば、PivotItem全体を占めるCanvasがありますか?このようなもの:
<phone:Pivot>
<phone:Pivot.Items>
<phone:PivotItem Header="menu">
<Canvas x:Name="Canvas" />
</phone:PivotItem>
<phone:PivotItem Header="game" />
</phone:Pivot.Items>
</phone:Pivot>
その場合、キャンバスの高さを取得するのは非常に簡単です。
Debug.WriteLine(this.Canvas.ActualHeight);
注:プロパティは、イベントActualHeight
の前に入力されません。Loaded
したがって、コンストラクターまたはメソッドから読み取ろうとしている場合OnNavigatedTo
、プロパティは0になります。
完全なXAMLコード:
<phone:PhoneApplicationPage
x:Class="WP7ForumTest.Page3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
Loaded="Page_Loaded">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:Pivot>
<phone:Pivot.Items>
<phone:PivotItem Header="menu">
<Canvas x:Name="Canvas" />
</phone:PivotItem>
<phone:PivotItem Header="game" />
</phone:Pivot.Items>
</phone:Pivot>
</Grid>
</phone:PhoneApplicationPage>
そして、コードビハインド:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show(this.Canvas.ActualHeight.ToString());
}