[英]How to bind image with BitmapImage in windows phone 8?
<Image Height="100" Width="100" Margin="12,0,9,0">
<Image.Source>
<BitmapImage UriSource="{Binding ImgURL}" CreateOptions="BackgroundCreation"/>
</Image.Source>
</Image>
我不知道如何用控件BitmapImage
绑定图像。
帮我!
在.cs文件中,您将源设置如下
1.)给您的XAML图像控件命名,例如x:Name="img"
2.) img.Source = new BitmapImage(new Uri(URL, UriKind.RelativeOrAbsolute))
URL =您在ImgURL
中获得哪个链接
希望对您有帮助。
编辑
ImageSource imgSource = null;
BitmapImage bm = new BitmapImage(new Uri(URL, UriKind.RelativeOrAbsolute));
imgSource = bm;
img.Source = imgSource;
恕我直言,您可以尝试从viewmodel
直接绑定
private Uri _imgURL;
public Uri ImgURL
{
get { return _imgURL; }
set
{
_imgURL= value;
RaisePropertyChanged(() => ImgURL);
}
}
//Load your data from here
public void LoadData()
{
Uri = new Uri(@"/sampleImages/cherries_larger.jpg",UriKind.RelativeOrAbsolute);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.