private void lstMails_MouseDoubleClick(object sender, MouseButtonEventArgs e) { ListBox listBox = (ListBox)sender; StringItem item = (StringItem)listBox.SelectedItem; if (item != null) { ServerSchema schema = (ServerSchema)listBox.DataContext; string fileName = schema.ExternalProgram; if (File.Exists(item.Item) && !String.IsNullOrEmpty(fileName)) { fileName = fileName.Trim(); /* * if (fileName.Contains(Tools.sExternalProgVar)) * { * fileName.Replace(Tools.sExternalProgVar, item.Item); * } * else * { * fileName = fileName.TrimEnd(' '); * fileName = fileName + " " + item.Item.Trim(); * } */ Process p = new Process(); p.StartInfo.FileName = fileName; p.StartInfo.Arguments = item.Item.Trim(); try { p.Start(); } catch (FileNotFoundException ex) { MessageBox.Show("File not found: " + p.StartInfo.FileName, "File not found", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show(ex.Message + " " + p.StartInfo.FileName, "Unknown Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
private void lstMails_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { ListBox listBox = (ListBox)sender; ServerSchema serverSchema = (ServerSchema)listBox.DataContext; IList selList = listBox.SelectedItems; StringItem[] fileIndex = new StringItem[selList.Count]; selList.CopyTo(fileIndex, 0); foreach (StringItem file in fileIndex) { serverSchema.MailDir.Remove(file.Item); serverSchema = (ServerSchema)listBox.DataContext; } serverSchema.MailsCount = CountMails(serverSchema.MailDir.ToArray <String>()); lstMails.GetBindingExpression(ListBox.ItemsSourceProperty).UpdateTarget(); } }