我所试图做的是如此简单,但我有一个很难使其工作。我看到沿着相同的路线有些职位,但我仍然有问题。

我有称为mnuA一个菜单项对象。我想要的是在C#编程设置图标属性。我曾尝试以下

A)mnuA.Icon = new BitmapImage{UriSource = new Uri(@"c:\icons\A.png")}; 结果:代替显示实际图标的,我得到的类名(System.Windows.Media.Imaging.BitmapImage

b)中mnuA.Icon = new BitmapImage(new Uri(@"c:\icons\A.png")); 结果:代替显示实际图标的,我得到的图像(file:///c:/icons/A.png)的路径

我在做什么错了?我真的需要一个转换器类对于这样简单的东西?

有帮助吗?

解决方案

尝试这种情况:

Image img = new Image();
img.Source = new BitmapImage(new Uri(@"c:\icons\A.png"));
mnuA.Icon = img;

其他提示

可能是一个长镜头,但尝试是这样的:

  

开放的U =新的URI(...); mnuA.Icon =新   的BitmapImage(U);

似乎什么事情发生的是,你的图标是越来越转换为字符串。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top