dkarzon
dkarzon

Reputation: 8038

WP7 Binding a local icon from a path

I'm using MVVM to bind my model data to a listbox on Windows Phone 7 but I cant figure out how to bind an icon to the list. I have an image in the template which is bound to the Icon property which is something like "/icons/icon-wo.png"

<Image Height="60" VerticalAlignment="Top" Width="60" Source="{Binding Icon}" Margin="0,0,12,0"/>
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" VerticalAlignment="Top" FontSize="29.333"/>

But the image doesnt show up, so I tried using a ValueConverter

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    return new BitmapImage(new Uri(value.ToString()));
}

How do I make this work pointing to local image file?

Upvotes: 0

Views: 849

Answers (1)

Matt Lacey
Matt Lacey

Reputation: 65556

You need to be using a Relative Uri and you need to make sure that the "Build Action" on the image is set to Content.

Update:

This works for me in a new project:

<Image Height="100" Source="{Binding}" />

Then in the code behind:

this.DataContext = new Uri("/ApplicationIcon.png", UriKind.Relative); 

Upvotes: 2

Related Questions