Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Issues With ImageSource Binding

$
0
0

Hi there, I have ran into a bit of a snag on a project. I am currently using a wcf service that returns an object which has a property called "ImageDataSource" which is the bytes of a bitmap image. I am binding the list view to a Observablecollection of the object returned and all looks well because the list view will display the two rows where the image will be but all I ever get to show up is the following..

What I am I doing wrong? I notice that my get accessor is never called on the ImageSource Property called "ImageDataSource"

Here is the code.
XAML

<Label TextColor="White" Text="Photos:" FontSize="Small" HorizontalOptions="Center"/>
                <ListView x:Name="listView" ItemsSource="{Binding PhotoList}">
                <DataTemplate>
                    <ViewCell>
                        <StackLayout BackgroundColor="#0099ff" Padding="4,0,0,0"
                        Orientation="Vertical">
                            <StackLayout Orientation="Horizontal" >
                                <ImageCell ImageSource="{Binding ImageDataSource}" HeightRequest="250" WidthRequest="250" />
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
        </ListView>

Property

public ImageSource ImageDataSource
        {
            get
            {
                return _imgSource;
            }
            set 
            {
                if (_imgSource != value) 
                {
                    _imgSource = value;
                    RaisePropertyChanged ("ImageDataSource");
                }
            }
        }

Class
`public class ImageData :ViewModelBase
{
private byte[] _imgBytes;
private ImageSource _imgSource;

    public void AssignBytesToImageSource()
    {
        ImageSource source = ImageSource.FromStream(() => new MemoryStream(this.ImgBytes));
        ImageDataSource = source;
    }


    public byte[] ImgBytes {
        get {
            return _imgBytes;
        }
        set {
            _imgBytes = value;
            RaisePropertyChanged ("ImgBytes");
        }
    }

    public ImageSource ImageDataSource
    {
        get
        {
            return _imgSource;
        }
        set 
        {
            if (_imgSource != value) 
            {
                _imgSource = value;
                RaisePropertyChanged ("ImageDataSource");
            }
        }
    }
}

`


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>