assume there is a folder "G:\Chargesheets\TestImage\thumbs\" with a bunch of thumbnails
I can display thos thumbnails just fine using the ReturnI subroutine. only I need to be able to move or delete the files from that folder, which I can not do while the program is running because of a file lock.
If I use the ReturnIMs subroutine I can delete and or move the files in that folder, but the listbox just shows a blank box for each image in the folder.
i think the problem is in this part of the xml Source="{Binding
UriSource}"
i have tried changing UriSource to MemoryStream but that did not work. any ideas would be appreciated.
XML source
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="794.223" Width="1076.351">
<Window.Resources>
<Style TargetType="{x:Type ListView}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Border
BorderBrush="Black"
BorderThickness="4"
CornerRadius="5"
Margin="6"
>
<Image
Source="{Binding UriSource}"
Stretch="Fill"
Width="144" Height="200"
/>
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter
Property="ScrollViewer.HorizontalScrollBarVisibility"
Value="Disabled"
/>
<Setter Property="SelectionMode" Value="Extended"/>
</Style>
</Window.Resources>
<Grid Margin="0,92,0,22">
<ListView x:Name="LBox" Margin="10,10,122,10" VerticalContentAlignment="Stretch" SelectionMode="Multiple"/>
<Label x:Name="Working" Content="Working" HorizontalAlignment="Left" Margin="10,60,0,0" VerticalAlignment="Top" Visibility="Hidden" Background="#FFEE1616"/>
</Grid>
</Window>
VB source
Imports System.IO
Class MainWindow
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Dim IPath As String = "G:\Chargesheets\TestImage\thumbs\"
LBox.ItemsSource = LoadImages(IPath, 0)
End Sub
Public Function LoadImages(IPath As String, AddPercent As Decimal) As List(Of BitmapImage)
Dim rImages As New List(Of BitmapImage)()
Dim rImageDir As New DirectoryInfo(IPath)
For Each rImageFile As FileInfo In rImageDir.GetFiles("*.png")
rImages.Add(ReturnI(rImageFile.FullName))
Next
Return rImages
End Function
Private Function ReturnI(Fpath As String) As BitmapImage
Dim BmpImage As BitmapImage
BmpImage = New BitmapImage()
BmpImage.BeginInit()
BmpImage.CacheOption = BitmapCacheOption.OnLoad
BmpImage.UriSource = New Uri(Fpath, UriKind.RelativeOrAbsolute)
BmpImage.EndInit()
Return BmpImage
End Function
Private Function ReturnIMs(Fpath As String) As BitmapImage
Dim Buffer() As Byte
Buffer = File.ReadAllBytes(Fpath)
Dim bitmapImage = New BitmapImage()
Using stream As Stream = New MemoryStream(DirectCast(Buffer, Byte()))
bitmapImage.BeginInit()
bitmapImage.CacheOption = BitmapCacheOption.OnLoad
bitmapImage.StreamSource = stream
bitmapImage.EndInit()
bitmapImage.Freeze()
Return bitmapImage
End Using
End Function
End Class