I have an image posted on a page as shown below.
<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>
this is the whole XAML page, the image can be downloaded from http://i.ytimg.com/vi/wNKKCHv-oOw/hqdefault.jpg
The code behind contains some logic for handling 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; } }
If someone can try this, he / she may find that StrechToFill trims the contents of the image from below, as I expect it to crop it evenly from the top and bottom and save the contents of the image in the image control center.
HOpe I made it clear, if not, consider making a sample from the code provided. Thank you very much.
source share