繁体   English   中英

更改所有图像坐标[Windows Store App,C#/ XAML]

[英]Change all images coordinates [Windows Store App, C#/XAML]

我的项目中有很多图像和多个页面。 我希望我的项目支持多屏幕分辨率。 我已经尝试过viewbox,但无法成功,因此我尝试了一张图像

private void setResolution()
    {
        var bounds = Window.Current.Bounds;
        ratioHeight = bounds.Height / standartHeight;
        ratioWidth = bounds.Width / standartWidth;

        Canvas.SetLeft(img1, Canvas.GetLeft(img1) * (ratioWidth));
        Canvas.SetTop(img1, Canvas.GetTop(img1) * (ratioHeight));
        img1.Width = img1.ActualWidth * (ratioWidth);
        img1.Height = img1.ActualHeight * (ratioHeight);
    }

它起作用了,但是太长了,很难在大约500张照片上应用。

有什么办法可以将所有图像放在舞台上并立即更改其坐标

对不起我的英语不好。

公认的解决方案(Microsoft推荐)是使用网格进行放置,并使用多个图像来应对多种分辨率。 他们的解决方案将提供元素的动态放置并加载正确的图像。

看看他们的Windows Phone 8多分辨率应用程序页面

(将代码粘贴到此处太多了)。

public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
    {
        if (depObj != null)
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                if (child != null && child is T)
                {
                    yield return (T)child;
                }

                foreach (T childOfChild in FindVisualChildren<T>(child))
                {
                    yield return childOfChild;
                }
            }
        }
    }

foreach (Image Images in FindVisualChildren<Image>(pageMain))
        {
            Canvas.SetLeft(Images, Canvas.GetLeft(Images) * (ratioWidth));
            Canvas.SetTop(Images, Canvas.GetTop(Images) * (ratioHeight));
            Images.Width = Images.ActualWidth * (ratioWidth);
            Images.Height = Images.ActualHeight * (ratioHeight);
        }

它为我工作(pageMain是Page的名称)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM