开发者

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?


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); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜