EventToCommand.cs 948 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Input;
  8. using System.Windows.Interactivity;
  9. namespace CyberX8_MainPages.Sequence
  10. {
  11. public class EventToCommand : TriggerAction<DependencyObject>
  12. {
  13. public ICommand Command
  14. {
  15. get { return (ICommand)GetValue(CommandProperty); }
  16. set { SetValue(CommandProperty, value); }
  17. }
  18. public static readonly DependencyProperty CommandProperty =
  19. DependencyProperty.Register("Command", typeof(ICommand), typeof(EventToCommand), new PropertyMetadata(null));
  20. protected override void Invoke(object parameter)
  21. {
  22. if (Command != null
  23. && Command.CanExecute(parameter))
  24. {
  25. Command.Execute(parameter);
  26. }
  27. }
  28. }
  29. }