eYe
eYe

Reputation: 1733

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

I have an image path declared as following:

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

I try to add a simple property that returns an ImageSource to my ViewModel as following:

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

Then bind in XAML:

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

Why does this not work, while:

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

Works as expected?

Upvotes: 0

Views: 942

Answers (1)

Domysee
Domysee

Reputation: 12846

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

This works because ImageSource has a value converter (ImageSourceConverter) attached to it, which automatically converts strings to image sources.

The first case should work too (and does in my test project).

Upvotes: 2

Related Questions