Hello, Welcome to Micorosoft Q&A,
cannot access the file because it is being used by another process
It's by-design, the image file was using by the image control when you delete it. if you want to delete used image file, you need dispose it at first
private async void Button_Click(object sender, RoutedEventArgs e)
{
var folder = ApplicationData.Current.LocalFolder;
//check file exists and delete
var file = await folder.GetFileAsync("test.png");
DisposeImage();
await file.DeleteAsync(StorageDeleteOption.Default);
}
private void DisposeImage()
{
imageHolder.Source = null;
GC.Collect();
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.