C# 弹出窗口中的图像方向

C# 弹出窗口中的图像方向,c#,image,silverlight,windows-phone-8,windows-phone,C#,Image,Silverlight,Windows Phone 8,Windows Phone,我正在开发WindowsPhone8应用程序 我有一个正在弹出窗口中显示的图像。但我有一些标准,比如 如果图像宽度>图像高度-以横向模式显示否则以纵向模式显示 那么我们如何才能做到这一点呢?我搜索了这个,发现弹出窗口没有定向属性 double actualHeight = Application.Current.Host.Content.ActualHeight; double actualWidth = Application.Current.Host.Content.ActualWidth;

我正在开发WindowsPhone8应用程序

我有一个正在弹出窗口中显示的图像。但我有一些标准,比如

如果图像宽度>图像高度
-
以横向模式显示
否则
以纵向模式显示

那么我们如何才能做到这一点呢?我搜索了这个,发现弹出窗口没有定向属性

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;
编辑

这也是我尝试过的:

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;
试试这个

        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;

我已经试过了,对于
横向模式,我已经将rt.Angle设置为0但图像仍显示在肖像设置中。角度=360;我想您需要为旋转变换设置CenterX和CenterY属性,在这里,这将帮助您了解如何相对于原点旋转。是的,在添加CenterX和CenterY后它可以工作,我有一个40x40的图像,我将CenterX和CenterY设置为20,然后将纵向角度设置为90,横向角度设置为0,它可以工作。请查看我的编辑,它仍然只在
纵向模式下显示