C#/WPF/Surface プログラミングは初めてです。
私は aLibraryStack
で aScatterViewItem
を使用していScatterView
ます:
<Grid Name="DataGrid" Background="LightBlue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.Resources>
<DataTemplate x:Key="LibraryItemTemplate">
<Viewbox Stretch="Uniform">
<Image Source="{Binding}" />
</Viewbox>
</DataTemplate>
<!-- Styles to ensure each library control uses the above defined templates -->
<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>
のにaObservableCollection
を設定してライブラリ スタックを埋めます。は、画像へのファイル パスである文字列で構成されます。ItemsSource
LibraryStack
ObservableCollection
ObservableCollection<string> oc = new ObservableCollection<string>(System.IO.Directory.GetFiles(folder));
LibraryStack1.ItemsSource = ocs;
これScatterViewItem
で、ドラッグ アンド ドロップですべての画像が含まれるようになりました。
LibraryStack
次に、 /からすべての画像をクリアScatterViewItem
し、フォルダー内のすべてのファイル/画像を削除します。
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 は空ですが、ファイルを削除すると常に例外がスローされます ( File.Delete(file)
):
System.IO.IOException: 別の別のプロセスによって使用されているため、プロセスはファイル 'xyz' にアクセスできません。System.IO.__Error.WinIOError(Int32 errorCode, String MaybeFullPath) で System.IO.File.Delete(String path) で ...
オーバーを削除するFileInfo
と、同じ例外がスローされます。
私は何をすべきか?