private void Deleting(object sender, RoutedEventArgs e)
{
MessageBoxResult message = MessageBox.Show(
"The file will be permanently deleted. Continue?",
"Delete File",
MessageBoxButton.OKCancel
);
if (message == MessageBoxResult.OK)
{
LongListSelector selector = sender as LongListSelector;
SoundData data1 = selector.SelectedItem as SoundData;
//control goes inside this block
if (selector == null)
{
return;
}
if (data1 == null)
return;
}
}
我必須能夠從長列表選擇器訪問該數據。刪除事件處理程序來自上下文菜單按鈕如何從上下文菜單中的選項調用longlistselector事件
此代碼能夠引用longlistselector中的選項。由於Venkatapathi拉朱求助
public void Deleting(object sender, RoutedEventArgs e)
{
SoundData data1 = (sender as MenuItem).DataContext as SoundData;
MessageBoxResult message = MessageBox.Show(
"The file will be permanently deleted. Continue?",
"Delete File",
MessageBoxButton.OKCancel
);
if (message == MessageBoxResult.OK)
{
私人無效LongListSelector_SelectionChanged(對象發件人,SelectionChangedEventArgs E) { LongListSelector選擇=發送者作爲LongListSelector;
if (selector == null)
return;
SoundData data = selector.SelectedItem as SoundData;
if (data == null)
return;
if (File.Exists(data.FilePath))
{
AudioPlayer.Source = new Uri(data.FilePath, UriKind.RelativeOrAbsolute);
}
else
{
using (var storageFolder = IsolatedStorageFile.GetUserStoreForApplication())
{
//Breakpoint
using (var stream = new IsolatedStorageFileStream(data.FilePath, FileMode.Open, storageFolder))
{
AudioPlayer.SetSource(stream);
}
}
}
我收到此錯誤信息 型「System.IO.IsolatedStorage.IsolatedStorageException」的異常出現在mscorlib.ni.dll但在用戶代碼中沒有處理
非常感謝。是的,我正在關注Bob Tabor的視頻。 IsolatedStorageFile isofile = IsolatedStorageFile.GetUserStoreForApplication(); isofile.DeleteFile(data1.FilePath); isofile.DeleteFile(data1.Title); App.ViewModel.CustomSounds.Items.Remove(data1);這將刪除我隔離的存儲文件,但該按鈕仍保留在頁面中。爲什麼它沒有被刪除? – seshagopalan
嘗試在App.ViewModel.CustomSounds.Items.Remove(data1);行後面添加App.ViewModel.LoadData();' 接受它,如果它適合您的答案,以便其他人不必查看此問題沒有答案。 –
謝謝。是的,我在前面提到過。無論如何將問題設置爲「解決」這樣的事情。我是新的stackoverflow和windowsphoneapp開發。同時,添加App.ViewModel.LoadData();不適合我。它仍在列表中。當我點擊它時,控制將會退出應用程序。 – seshagopalan