I am new to C # / WPF / Surface programming.
I use LibraryStack in ScatterViewItem in ScatterView :
<Grid Name="DataGrid" Background="LightBlue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Grid.Resources> <DataTemplate x:Key="LibraryItemTemplate"> <Viewbox Stretch="Uniform"> <Image Source="{Binding}" /> </Viewbox> </DataTemplate> <Style TargetType="{x:Type s:LibraryStack}"> <Setter Property="ItemTemplate" Value="{StaticResource LibraryItemTemplate}"/> </Style> <Style TargetType="{x:Type s:LibraryBar}"> <Setter Property="ItemTemplate" Value="{StaticResource LibraryItemTemplate}"/> </Style> <DataTemplate x:Key="itemTemplate"> <Image Source="{Binding XPath=@FullPath }"/> </DataTemplate> </Grid.Resources> <s:ScatterView HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <s:ScatterViewItem Name="ScatterViewItem1" Background="DarkGray" MinWidth="800" MinHeight="800" Orientation="0.0" CanRotate="False"> <s:LibraryStack Name="LibraryStack1" Background="Transparent" MinWidth="800" MinHeight="800" AllowDrop="True" > </s:LibraryStack> </s:ScatterViewItem> </s:ScatterView> </Grid>
I populate the library stack by setting the ObservableCollection to ItemsSource LibraryStack . ObservableCollection consists of strings that are file paths to images.
ObservableCollection<string> oc = new ObservableCollection<string>(System.IO.Directory.GetFiles(folder)); LibraryStack1.ItemsSource = ocs;
Now I have a ScatterViewItem with all the images in it with drag and drop.
Then I want to clear all the images from LibraryStack / ScatterViewItem and delete all the files / images in the folder:
oc=null; LibraryStack1.ItemsSource = null; string[] files = Directory.GetFiles(folder); foreach (String file in files) { try { File.Delete(file); } catch (Exception f) { Console.WriteLine(f); } }
ScatterViewItem on the screen is empty, but there is always an exception deleting files ( File.Delete(file) ):
System.IO.IOException: The process cannot access the "xyz" file because it is being used by another other process. in System.IO .__ Error.WinIOError (Int32 errorCode, String maybeFullPath) in System.IO.File.Delete (String path) ...
Removing more than FileInfo raises the same exception.
What should I do?
source share