如何从代码隐藏设置 URI

How to set an URI from code-behind

我见过几个这样的例子

How to Set Image Resource URI from Code-Behind

还没看懂

如果我有以下解决方案

我想为 ita.png

设置 uri
 Stream iconStream = Application.GetResourceStream(new Uri(?????)).Stream;
  notifyIcon.Icon = new System.Drawing.Icon(iconStream);

谢谢

您可以使用 here

中描述的 pack URI 语法

在你的情况下它会是这样的:

  Stream iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/Resources/Images/ITA.png")).Stream;
  notifyIcon.Icon = new System.Drawing.Icon(iconStream);