private void StackPanelItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { try { StackPanel stackPanelItem = (StackPanel)sender; if (stackPanelItem != null) { ItemVM itemVM = (ItemVM)stackPanelItem.DataContext; if (itemVM != null) { // Detect double clicks if (e.ClickCount == 2 && !itemVM.IsGroup) { clickedObjectHashCode = stackPanelItem.GetHashCode(); } } } } catch (Exception ex) { Error.ShowDialog(ex); } }
private void StackPanelItem_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { try { StackPanel stackPanelItem = (StackPanel)sender; if (stackPanelItem != null) { if (clickedObjectHashCode.HasValue) { if (clickedObjectHashCode.Value == stackPanelItem.GetHashCode()) { // We have a click ItemVM itemVM = (ItemVM)(stackPanelItem.DataContext); if (itemVM != null) { if (!itemVM.IsGroup) { try { // Working in general //Process.Start(itemVM.Target); //// Working in general //// https://stackoverflow.com/questions/5255086/when-do-we-need-to-set-useshellexecute-to-true //using (Process process = new Process()) //{ // process.StartInfo.UseShellExecute = true; // process.StartInfo.FileName = target; // // process.StartInfo.Arguments = itemVM.Target; // bool result = process.Start(); //} // Working somehow // Open Control Panel Items using Shell (COM) // http://tech-giant.blogspot.com/2009/07/open-control-panel-items-using-shell.html // Shell shell = new Shell(); // shell.ControlPanelItem("appwiz.cpl"); // shell.ControlPanelItem(itemVM.Target); // Working best for third party control panel items // Process.Start("explorer.exe", itemVM.Target); // Working best for third party control panel items // Process.Start("explorer", itemVM.Target); /* * // Working best for third party control panel items * // https://stackoverflow.com/questions/5255086/when-do-we-need-to-set-useshellexecute-to-true * using (Process process = new Process()) * { * process.StartInfo.UseShellExecute = true; * process.StartInfo.ErrorDialog = true; * process.StartInfo.FileName = "explorer.exe"; * process.StartInfo.Arguments = itemVM.Target; * bool result = process.Start(); * } */ /* * // Working best for third party control panel items * // https://stackoverflow.com/questions/5255086/when-do-we-need-to-set-useshellexecute-to-true * string shortcutFilePath = Path.Combine(Helper.GetShortcutsDirectoryPath(), itemVM.Guid + itemVM.Ext); * using (Process process = new Process()) * { * process.StartInfo.UseShellExecute = true; * process.StartInfo.ErrorDialog = true; * process.StartInfo.FileName = "explorer.exe"; * process.StartInfo.Arguments = shortcutFilePath; * bool result = process.Start(); * } */ string shortcutsPath = Path.Combine(Helper.GetShortcutsPath(), itemVM.Guid + itemVM.Ext); Process.Start(shortcutsPath); } catch (System.ComponentModel.Win32Exception ex) { string exceptionMessage = $"Error code: {ex.ErrorCode.ToString()} \n"; exceptionMessage += $"{ex.Message}. \n"; exceptionMessage += "Please make sure the shortcut target is correct!"; MessageBox.Show(this, exceptionMessage, "Exception", MessageBoxButton.OK, MessageBoxImage.Exclamation); } catch (Exception ex) { MessageBox.Show(this, ex.ToString(), "Exception", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } } clickedObjectHashCode = null; } } } } catch (Exception ex) { Error.ShowDialog(ex); } }