I have image bytes in a SQLite database. when I want to get one image, I got it by id and converted the bytes of the image into a bitmap. But when I want to associate a data list with a listBox, then I cannot bind image control directly to bytes.
My Xaml code is here.
<ListBox Background="Transparent" Margin="-5,2,-5,10" BorderThickness="0" MaxHeight="680" Grid.Row="1" x:Name="listBoxobj" SelectionChanged="listBoxobj_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="400" Margin="0,-10,0,0" >
<Grid x:Name="pro_work_grid" Width="400" Height="120" Margin="0,0,0,0"
VerticalAlignment="Bottom" Background="#31b1b0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
//Image will give here image bytes. not the source.
// Not know how to bind this with list,,which contain image bytes
<Image x:Name="work_pic" Source="{Binding image}" Width="120" Height="120"
Stretch="Fill" VerticalAlignment="Center" Margin="0,0,0,0"
Grid.ColumnSpan="1" HorizontalAlignment="Left"/>
<TextBlock x:Name="pro_name1" Foreground="White" VerticalAlignment="Top" Grid.ColumnSpan="2" Margin="130,10,0,0"
Text="{Binding category}" FontSize="26" FontWeight="Bold">
</TextBlock>
<TextBlock x:Name="pro_title1" VerticalAlignment="Center" Grid.ColumnSpan="2" Margin="130,10,0,0"
Text="{Binding title}" FontSize="20" Foreground="White">
</TextBlock>
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I have a text block binding directly to the categories and title .. that are on the list.
when my ListBox page loads, then the code works,
private void ReadContactList_Loaded(object sender, RoutedEventArgs e)
{
ReadAllContactsList dbcontacts = new ReadAllContactsList();
DB_ContactList = dbcontacts.GetAllContacts();
if (DB_ContactList.Count > 0)
{
}
listBoxobj.ItemsSource = DB_ContactList.OrderByDescending(i => i.Id).ToList();
}
I can get the image from one byte of the image. but here is a list of displayed images, since I can get bytes and convert them to image management and show them separately in image management. Here are my listbox items

? ,, Advance
.
if (args != null)
{
if (args.Files.Count == 0) return;
view.Activated -= viewActivated;
StorageFile storageFile = args.Files[0];
string pro_img_path = storageFile.Path;
var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
filebite = new byte[stream.Size];
using (DataReader reader = new DataReader(stream))
{
await reader.LoadAsync((uint)stream.Size);
reader.ReadBytes(filebite);
}
.
using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
{
using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))
{
writer.WriteBytes((byte[])pro_pic_byts);
writer.StoreAsync().GetResults();
}
var img1 = new BitmapImage();
img1.SetSource(ms);
pro_pic.Source = img1;
}