List of WPF images from the database

(How long have we been using OpenIDs? It seems that I am not connected to any provider, and no frequently asked questions on the planet seem to tell you what to do when you lose OpenID. I had to create a new account. Argh! )

I am trying to populate a (carousel) list from a database, but I cannot get the images to display. Each example on the network assumes that you have two or three jpeg in a folder, not in memory :(

My element class:

public class PicCollection : ObservableCollection<CarouselItem>
{
    public PicCollection()
    {

    }
}
public class CarouselItem
{
    public int ItemID { get; set; }
    public string ItemName { get; set; }
    public string ItemDesc { get; set; }
    public Image ItemImage { get; set; }

    public CarouselItem(int NewItemID, string NewItemName, string NewItemDesc, Image newItemImage)
    {
        this.ItemID = NewItemID;
        this.ItemName = NewItemName;
        this.ItemDesc = NewItemDesc;
        this.ItemImage = newItemImage;
    }
}

I successfully populate PicCollection from db (using an array of bytes for the image) and try to display the name and image using

    <DataTemplate x:Key="TestDataTemplate2"  >
        <StackPanel Orientation="Horizontal">
            <TextBlock x:Name="CarName" 
                           Text="{Binding ItemName}"  
                           Padding="15,15"
                           Foreground="Yellow" />
            <Image Source="{Binding Source=ItemImage}"
                   Stretch="Fill" />
            </StackPanel>
    </DataTemplate>

Listbox is simple:

<ListBox Name="lstTest" ItemsSource="{StaticResource TestDataSource}" 
                ItemTemplate="{StaticResource TestDataTemplate2}"></ListBox>

ItemName , ItemImage - . {Binding ItemImage}. {Binding Path=ItemImage}, ItemImage , , .

. , . , ItemImage, . ?

+3
2

ItemImage Image (control). ImageSource, System.Windows.Media.Imaging.BitmapImage. <Image Source="{Binding ItemImage}" />.

+3

"ItemImage" , ContentControl :

<ContentControl Content="{Binding Image}" />
0

Source: https://habr.com/ru/post/1716747/


All Articles