如何在windows phone 8中绑定图像与BitmapImage


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

最新更新