![](/img/trans.png)
[英]Binding AutocompleteBox in WP7 Application from an ObservableCollection<>, created by a Local Database
[英]WP7 Binding a local icon from a path
我正在使用MVVM将我的模型数据绑定到Windows Phone 7上的列表框,但我无法弄清楚如何将图标绑定到列表。 我在模板中有一个图像绑定到Icon属性,就像“/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"/>
但图像没有显示,所以我尝试使用ValueConverter
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return new BitmapImage(new Uri(value.ToString()));
}
如何使此工作指向本地图像文件?
您需要使用Relative
Uri,并且需要确保图像上的“Build Action”设置为Content
。
更新:
这在我的新项目中适用于我:
<Image Height="100" Source="{Binding}" />
然后在代码背后:
this.DataContext = new Uri("/ApplicationIcon.png", UriKind.Relative);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.