我的应用程序中出现了一些奇怪的黑魔法。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元素的背景属性:
<Border x:Name="SplashScreen"
Background="{StaticResource SplashScreenImageBrush}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
所以,问题是,当我调试应用程序在WP8仿真器或WP8设备上的一切工作正常。 在未经调试的情况下启动应用程序时,Border background属性呈现为白色。 图像文件包含在项目中,并将“生成操作”设置为“内容”。
此外,如果我将ImageSource直接设置为图像路径,则一切正常。
所以,这个问题似乎是MultiResImageChooser,但我不知道什么可能是错的。
任何形式的帮助或提示将不胜感激。
顺便说一句,这个问题没有得到再现W上WP7.1设备和仿真器。
我敢打赌:'ResolutionHelper.CurrentResolution'由于某种原因(计时问题?)无法正常工作,所以执行了交换机的“默认”分支。因此,您的绑定失败,画笔不会被初始化,而是会变为白色。从那里开始,我会首先确认“默认”分支的执行情况,例如通过放置特定图像而不是抛出异常。然后,如果我的理论是正确的,请查看“ResolutionHelper”以了解发生了什么。 – 2013-05-06 14:39:54
@KooKiz谢谢!你的投注确实让我指向了正确的方向。 ResolutionHelper实际上是崩溃。我修好了,现在一切正常。谢谢! – Mike 2013-05-06 19:18:26