【问题标题】:Resolution dependent backgrounds in Windows Phone 8Windows Phone 8 中的分辨率相关背景
【发布时间】:2013-11-11 10:17:13
【问题描述】:

我正在关注this MSDN 文章在 Windows Phone 8 中创建与分辨率相关的背景,但它总是显示空白背景。

有人知道它有什么问题吗?有人有其他解决方案吗?

【问题讨论】:

  • 但在较新的型号上它是更高分辨率的黑色。
  • 我听不懂你在说什么。
  • 我没有得到你所尝试的,实际发生的与你预期的,等等。
  • 图像不显示,在设计时我可以在模拟器中看到图像根据主题显示为白色或黑色。

标签: c# image xaml windows-phone-8 resolution


【解决方案1】:
   public enum Resolutions { WVGA, WXGA, HD720p, HD };

    private static bool IsWvga
    {
        get
        {
            return App.Current.Host.Content.ScaleFactor == 100;
        }
    }

    private static bool IsWxga
    {
        get
        {
            return App.Current.Host.Content.ScaleFactor == 160;
        }
    }

    private static bool Is720p
    {
        get
        {
            return App.Current.Host.Content.ScaleFactor == 150;
        }
    }
    private static bool IsHD
    {
       get 
      { 
         return App.Current.Host.Content.ScaleFactor == 150; 
      }
    }

将此添加到类的顶部并使用这些静态变量来设置特定分辨率的图像。你说你想设置“分辨率依赖背景”,据我了解你想在背景上设置一些图像?如果您希望图像作为页面背景,则将LayoutRoot Grid 的ImageBrush 设置为像这样的分辨率特定图像(480x800.jpg、720x1280.jpg 等)

        ImageBrush image = new ImageBrush();
        if (IsWvga)
        {
            //set your bitmap
        }
        else if (IsWxga)
        {
            //set your bitmap
        }
        else if (Is720p)
        {
            //set your bitmap
        }
        else if(IsHD)
        {
           //set your bitmap
        }
        image.Stretch = Stretch.UniformToFill;

        LayoutRoot.Background = image;

如果您希望屏幕 UI 元素适合分辨率,则在 XAML 中将您的 UI 元素的 height 设置为 auto,或者在您的 OnNavigatedTo 事件上设置您的 UI 元素的分辨率特定高度页。这可能是您页面的任何需要适合的随机网格

        if (IsWvga)
        {
            grid.Height = 500;
        }
        else if (IsWxga)
        {
            grid.Height = 600;
        }
        else if (Is720p)
        {
            grid.Height = 700;
        }
        else if (IsHD)
        {
            grid.Height = 800;
        }

【讨论】:

  • 感谢您的回复,但我不想这样。我想遵循this 的方法,它更特定于 XAML
【解决方案2】:

MSDN 文章在 MultiResImageChooser 类中有错误,MultiResImageChooser 写为 MultiResImageChooserUri 并且相关 URI 缺少前导斜杠。下面给出了正确的类。

public class MultiResImageChooser
{
    public Uri BestResolutionImage
    {
        get
        {
            switch (ResolutionHelper.CurrentResolution)
            {
                case Resolutions.HD:
                    return new Uri("/Assets/MyImage.screen-720p.jpg", UriKind.Relative);
                case Resolutions.WXGA:
                    return new Uri("/Assets/MyImage.screen-wxga.jpg", UriKind.Relative);
                case Resolutions.WVGA:
                    return new Uri("/Assets/MyImage.screen-wvga.jpg", UriKind.Relative);
                default:
                    throw new InvalidOperationException("Unknown resolution type");
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 2013-05-01
    • 1970-01-01
    相关资源
    最近更新 更多