2015-05-22 45 views
0

我必須聲明如下成像路徑:爲什麼要Image.Source結合圖像路徑不以這種方式工作

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

我嘗試添加一個簡單的屬性,它返回一個ImageSource的到我的視圖模型如下:

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"/> 

按預期工作?

+0

第一個案例也應該工作,你確定你綁定到正確的屬性?也許datacontext是不同的,因爲封閉元素的綁定? – Domysee

回答

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

此操作,因爲ImageSource具有附着到其上的值轉換器(ImageSourceConverter),其自動地將字符串轉換爲圖像源。

第一個案例也應該工作(並在我的測試項目)。

相關問題