I am working on Windows Phone 8 application.
I have a image that is being displayed in PopUp. But i have a some criteria like.
if image width > image height
- display in landscape mode
else display in portrait mode
So how can we acheive this? i have searched for this and found that there is no orienation property for Popup.
double actualHeight = Application.Current.Host.Content.ActualHeight;
double actualWidth = Application.Current.Host.Content.ActualWidth;
Grid grid = new Grid();
grid.VerticalAlignment = VerticalAlignment.Center;
grid.HorizontalAlignment = HorizontalAlignment.Center;
grid.Height = actualHeight; //set height
grid.Width = actualWidth; //set width
grid.Background = new SolidColorBrush(Colors.White);
Image img = new Image();
img.VerticalAlignment = VerticalAlignment.Center;
img.HorizontalAlignment = HorizontalAlignment.Center;
img.Source = bitmapImage;
img.Tap += OnFullScreenImageTap;
//below i am passing the calculated imageWidth and imageHeight
if (imageWidth > imageHeight)
{
//Landscape
Debug.WriteLine("Display image in LANDSCAPE");
}
else if (imageWidth == imageHeight)
{
//Portrait
Debug.WriteLine("Display image in PORTRAIT");
}
else
{
//Portrait
Debug.WriteLine("Display image in PORTRAIT");
}
grid.Children.Add(img);
popUp.Child = grid; //set child content
this.LayoutRoot.Children.Add(popUp);
popUp.IsOpen = true;
EDIT
This is what i have tried as well:
RotateTransform rt = new RotateTransform();
rt.CenterX = 20;
rt.CenterY = 20;
img.VerticalAlignment = VerticalAlignment.Center;
img.HorizontalAlignment = HorizontalAlignment.Center;
img.Source = bitmapImage;
if (imageWidth > imageHeight)
{
//Landscape
rt.Angle = 0;
Debug.WriteLine("Display image in LANDSCAPE");
}
else if (imageWidth == imageHeight)
{
//Portrait
rt.Angle = 90;
Debug.WriteLine("Display image in PORTRAIT");
}
else
{
//Portrait
rt.Angle = 90;
Debug.WriteLine("Display image in PORTRAIT");
}
img.RenderTransform = rt;
Give this a try
double actualHeight = Application.Current.Host.Content.ActualHeight;
double actualWidth = Application.Current.Host.Content.ActualWidth;
Grid grid = new Grid();
grid.VerticalAlignment = VerticalAlignment.Center;
grid.HorizontalAlignment = HorizontalAlignment.Center;
grid.Height = actualHeight; //set height
grid.Width = actualWidth; //set width
grid.Background = new SolidColorBrush(Colors.White);
Image img = new Image();
img.VerticalAlignment = VerticalAlignment.Center;
img.HorizontalAlignment = HorizontalAlignment.Center;
img.Source = bitmapImage;
img.Tap += OnFullScreenImageTap;
RotateTransform rt = new RotateTransform
rt.CenterX = actualWidth / 2;
rt.CenterY = actualHeight / 2;
if (imageWidth > imageHeight)
{
//Landscape
rt.Angle = 0;
Debug.WriteLine("Display image in LANDSCAPE");
}
else if (imageWidth == imageHeight)
{
//Portrait
rt.Angle = 90;
Debug.WriteLine("Display image in PORTRAIT");
}
else
{
//Portrait
rt.Angle = 90;
Debug.WriteLine("Display image in PORTRAIT");
}
grid.Children.Add(img);
popUp.Child = grid; //set child content
this.LayoutRoot.Children.Add(popUp);
popUp.IsOpen = true;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.