【问题标题】:ImageBrush renders white when not debugging application不调试应用程序时 ImageBrush 呈现白色
【发布时间】:2013-05-06 13:16:18
【问题描述】:

我的应用出现了一些奇怪的黑魔法。

我在样式字典中定义了一个 ImageBrush:

<classes:MultiResImageChooser x:Key="MultiResImageChooser"/>

<ImageBrush x:Name="SplashScreenImageBrush"
            ImageSource="{Binding SplashScreenResolutionImage, Source={StaticResource MultiResImageChooser}}"
            Stretch="Fill" />`

MultiResImageChooser 类有一个简单的属性:

public class MultiResImageChooser
{
    public BitmapImage SplashScreenResolutionImage
    {
        get
        {
            switch (ResolutionHelper.CurrentResolution)
            {
                case Resolutions.HD720p:
                    return new BitmapImage(new Uri("/Images/SplashScreenImage.Screen-720p.jpg", UriKind.Relative));
                case Resolutions.WXGA:
                    return new BitmapImage(new Uri("/Images/SplashScreenImage.Screen-WXGA.jpg", UriKind.Relative));
                case Resolutions.WVGA:
                    return new BitmapImage(new Uri("/Images/SplashScreenImage.Screen-WVGA.jpg", UriKind.Relative));
                default:
                    throw new InvalidOperationException("Unknown resolution type");
            }
        }
    }
}

SplashScreenImageBrush 绑定到边框元素的背景属性:

<Border x:Name="SplashScreen" 
        Background="{StaticResource SplashScreenImageBrush}" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" />

所以,问题是当我在 WP8 模拟器或 WP8 设备上调试应用程序时,一切正常。 在未调试的情况下启动应用程序时,边框背景属性呈现为白色。 图像文件包含在项目中,并将 Build Action 设置为 Content。

此外,如果我将 ImageSource 直接设置为图像路径,则一切正常。

所以,问题似乎是 MultiResImageChooser,但我不知道它可能有什么问题。

任何形式的帮助或提示将不胜感激。

顺便说一句,这个问题不会在 w WP7.1 设备和模拟器上重现。

【问题讨论】:

  • 我敢打赌:ResolutionHelper.CurrentResolution 由于某种原因(时间问题?)不能正常工作,所以你的开关的“默认”分支被执行。因此,您的绑定失败,画笔没有被初始化,而是变成了白色。从那里开始,我首先确认“默认”分支的执行,例如通过放置特定图像而不是抛出异常。然后,如果我的理论是正确的,请查看ResolutionHelper 以了解发生了什么。
  • @KooKiz 谢谢!你的赌注确实为我指明了正确的方向。 ResolutionHelper 实际上正在崩溃。我修复了它,现在一切正常。谢谢!

标签: xaml windows-phone-8 windows-phone winrt-xaml


【解决方案1】:

我敢打赌:ResolutionHelper.CurrentResolution 由于某种原因(时间问题?)不能正常工作,所以你的开关的“默认”分支被执行。因此,您的绑定失败,画笔没有被初始化,而是变成了白色。从那里,我首先确认“默认”分支的执行,例如通过放置特定图像而不是抛出异常。然后,如果我的理论是正确的,请查看 ResolutionHelper 以了解发生了什么。

【讨论】:

    猜你喜欢
    • 2015-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 2011-03-20
    相关资源
    最近更新 更多