OpenLinkCommand.cs 736 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Diagnostics;
  3. using System.Windows.Input;
  4. namespace HandyControl.Interactivity;
  5. public class OpenLinkCommand : ICommand
  6. {
  7. public bool CanExecute(object parameter) => true;
  8. public void Execute(object parameter)
  9. {
  10. if (parameter is string link)
  11. {
  12. link = link.Replace("&", "^&");
  13. try
  14. {
  15. Process.Start(new ProcessStartInfo("cmd", $"/c start {link}")
  16. {
  17. UseShellExecute = false,
  18. CreateNoWindow = true
  19. });
  20. }
  21. catch
  22. {
  23. // ignored
  24. }
  25. }
  26. }
  27. public event EventHandler CanExecuteChanged;
  28. }