Mani
Mani

Reputation: 1374

bind absolute images to longlistselector in mvvm

I have downloaded a set of items from a web site and got text details into a binding class. In these i have image uri which i need to bind to the longlist selector along with other details. The problem is that I am not able to download, indeed there has been an exception in design view when i place a image converter itself.

Converter code:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var imageFile = value as string;

        if (imageFile != null)
        {
            BitmapImage image = new BitmapImage();
            image.CreateOptions = BitmapCreateOptions.BackgroundCreation;
            image.UriSource = new Uri("http://www.somewebsite.com/" + imageFile, UriKind.Absolute);

            return image;
        }
        else
            return null;

    }

LLS:

            <phone:LongListSelector.ItemTemplate>
                <DataTemplate>
                    <Grid Height="500" Margin="0,0,0,12">
                        <Grid.Resources>
                            <local:ImageConverter x:Name="imageConverter"/>
                        </Grid.Resources>
                        <Grid.Background>
                            <ImageBrush Stretch="Uniform" ImageSource="{Binding Path=ImgSrc, Converter={StaticResource imageConverter}}"/>
                        </Grid.Background>

Upvotes: 1

Views: 160

Answers (1)

Igor Ralic
Igor Ralic

Reputation: 15006

You really don't need to download it yourself. Just bind to the path string.

<DataTemplate>
    <Grid Height="500" Margin="0,0,0,12">
        <Grid.Background>
            <ImageBrush Stretch="Uniform" ImageSource="{Binding ImgSrc}"/>
        </Grid.Background>
    </Grid>
</DataTemplate>

Upvotes: 1

Related Questions