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 中的选项。感谢 Venkatapathi Raju 的帮助
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)
{
private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) { LongListSelector selector = sender as 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);
}
}
}
我收到此错误消息 mscorlib.ni.dll 中出现“System.IO.IsolatedStorage.IsolatedStorageException”类型的异常,但未在用户代码中处理