2014-02-24 70 views
0

我有以下代碼在圖像控件中顯示圖像。刪除在Windows Phone圖像控件中顯示的圖像

var stream = isolatedStorage.OpenFile(imageName, System.IO.FileMode.Open, System.IO.FileAccess.Read); 
BitmapImage bitmapImage = new BitmapImage(); 
bitmapImage.SetSource(stream); 
imageControl.Source = bitmapImage; 

我也想給用戶選項刪除圖像。我有以下代碼。

myImage.Source = null; 
isolatedStorage.DeleteFile(imageName); 

但是這會導致IsolatedStorageException和消息'無法刪除文件'。

我無法使用位圖的流源屬性或使用緩存選項,因爲Windows手機不支持它們。

任何其他解決方法?

回答

1

可能是您在刪除文件之前需要關閉fileStream

嘗試

stream.Close() 

或像這樣刪除文件前

OR

如果您isolatedStorage變量是IsolatedStorageFile類型,那麼你可以直接使用

isolatedStorage.DeleteFile("yourfilename.ext"); 
+0

你的 第一個解決方案有效第二個解決方案不起作用。它的類型IsolatedStorageFile只能通過IsolatedStorageFile.GetUserStoreForApplication()獲得。 – Curious

相關問題