如何在windows phone 8中用BitmapImage绑定图片?

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 = link 你在 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);
}