次のようにページに画像を配置しています
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Name="im" Source="/images/hqdefault.jpg" Height="250" Stretch="UniformToFill" VerticalAlignment="Center"/>
</Grid>
これはページ全体の XAML です。画像はhttp://i.ytimg.com/vi/wNKKCHv-oOw/hqdefault.jpgからダウンロードできます。
コード ビハインドには、PageOrientation_Change を処理するロジックが含まれています。
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
if (Orientation == PageOrientation.Landscape ||
Orientation == PageOrientation.LandscapeLeft ||
Orientation == PageOrientation.LandscapeRight)
{
im.Height = Application.Current.Host.Content.ActualWidth;
im.Width = Application.Current.Host.Content.ActualHeight;
im.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
im.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
}
else
{
im.Height = 250;
im.Width = Application.Current.Host.Content.ActualWidth;
}
}
誰かがこれを試してみると、StrechToFill が画像のコンテンツを下からトリミングすることに気付くかもしれませんが、私はそれが上と下から均等にトリミングされ、画像コンテンツが画像コントロール内の中央に置かれることを期待しています。
提供されたコードからサンプルを作成することを検討してください。どうもありがとう。