【问题标题】:BitmapImage Failing when trying to change image on a trigger c# UWP尝试更改触发器上的图像时BitmapImage失败c#UWP
【发布时间】:2021-10-04 17:51:28
【问题描述】:

我正在尝试根据 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" />

文件结构:

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

【问题讨论】:

    标签: c# uwp uwp-xaml bitmapimage


    【解决方案1】:

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

    如下:

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

    更多UWP中的URL scheme请参考:URI schemes

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 2012-12-04
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多