コメント
コメントの投稿
※名前とタイトルが入力されていないコメントでは他のコメントとの区別ができません。
入力されていないコメントには返信しませんのであらかじめご了承くださいませ。
using System;
using System.IO;
using Xamarin.Forms;
public class ImageSourceFromByteArrayConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
ImageSource imgSource= null;
if (value != null)
{
byte[] byteArray = (byte[])value;
imgSource= ImageSource.FromStream(() => new MemoryStream(byteArray));
}
return imgSource;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
<Image x:Name="imgPicture"
Aspect="AspectFill"
HeightRequest="100"
WidthRequest="100"
HorizontalOptions="StartAndExpand" />
//バインドするエンティティをインスタンス化する
CustomerInfo cInfo = new CustomerInfo
//Streamをバイト配列に変換する
cInfo.Picture = ImgConverter.GetByteArrayFromStream(stream);
//Imageコントロールのバインド方法を変更する
imgPicture.SetBinding(Image.SourceProperty,
new Binding("Picture",
BindingMode.Default,
new ImageSourceFromByteArrayConverter(),
null));
//バインドする
this.BindingContext = cInfo;
※名前とタイトルが入力されていないコメントでは他のコメントとの区別ができません。
入力されていないコメントには返信しませんのであらかじめご了承くださいませ。