为什么绑定图像路径到 Image.Source 不能这样工作

Why does binding image path to Image.Source does not work this way

我有一个图像路径声明如下:

public static string _edit_vector32 = "pack://application:,,,/Resources/Images/Icons/32/edit-vector2-32.png"; 

我尝试添加一个简单的 属性,即 returns 一个 ImageSource 到我的 ViewModel,如下所示:

public ImageSource ClockImage
{
    get
    { 
        return new BitmapImage(new Uri(RuntimeSettings._clock24)) as ImageSource;
    }
 }

然后绑定在XAML:

 <Image Source="{Binding ClockImage}"/>

为什么这不起作用,而:

 <Image Source="pack://application:,,,/Resources/Images/Icons/32/edit-vector2-32.png"/>

按预期工作?

<Image Source="pack://application:,,,/Resources/Images/Icons/32/edit-vector2-32.png"/>

之所以有效,是因为 ImageSource 附加了一个值转换器 (ImageSourceConverter),它会自动将字符串转换为图像源。

第一个案例也应该有效(在我的测试项目中也是如此)。