【发布时间】:2013-11-15 21:16:56
【问题描述】:
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 选择器 = 作为 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”类型的异常,但未在用户代码中处理
【问题讨论】:
标签: c# windows-phone-8 contextmenu longlistselector