【问题标题】:How to bind image with BitmapImage in windows phone 8?如何在 Windows Phone 8 中将图像与 BitmapImage 绑定?
【发布时间】:2015-10-19 04:53:53
【问题描述】:
<Image Height="100" Width="100" Margin="12,0,9,0">   
    <Image.Source>    
        <BitmapImage UriSource="{Binding ImgURL}" CreateOptions="BackgroundCreation"/>   
    </Image.Source>
</Image>

不知道怎么绑定图片和控件BitmapImage

帮帮我!

【问题讨论】:

  • 把你的模型绑定类。
  • 在代码中.cs如何绑定?你能告诉更多吗?

标签: image windows-phone-8 data-binding windows-phone-8.1 bitmapimage


【解决方案1】:

在 .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;

【讨论】:

  • 我想和Bitmap绑定,因为Bitmap可以清除图片缓存。
【解决方案2】:

恕我直言,您可以尝试从 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);
}

【讨论】:

    猜你喜欢
    • 2013-09-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2014-01-15
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    相关资源
    最近更新 更多