尝试更改触发器上的图像时 BitmapImage 失败 c# UWP

问题描述

我正在尝试根据 UWP 应用程序中的事件动态更改我所在的页面。当偶数被触发时,我检查一个简单的 if 语句,该语句通过并尝试将旧的背景图像设置为新的图像。我将代码简化为将确切 url(参见文件结构的图像)放入图像所在位置的位置,但我仍然收到错误消息。下面是错误

错误:System.ArgumentException:'错误 0x2624。调试资源字符串不可用。见http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.30319.0&File=mscorrc.dll&Key=0x2624"

这是受影响的代码

c# -- MainPage.xmal.cs
BackGroundImage.source = new BitmapImage(new Uri("/Assets/Images/Financial.png",UriKind.Relative));

XMAL --MainPage.xmal
<Image x:Name="BackGroundImage" Source="Assets/Images/Food.png" />

文件结构:

enter image description here

每当我触发改变背景的偶数时,我都会收到错误并且程序崩溃。有谁知道为什么?这是我第一次使用 BitmapImages 和 Uri。

解决方法

好吧,请尝试更改 URL 方案。

如下:

BackGroundImage.Source= new BitmapImage(new Uri("ms-appx:///Assets/Images/Financial.png"));

有关 UWP 中 URL 方案的更多详细信息,请参阅此:URI schemes