EventCommandTrigger.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. namespace OpenSEMI.ClientBase.Command
  8. {
  9. public sealed class EventCommandTrigger : CommandTrigger
  10. {
  11. #region Dependency Properties
  12. #region RoutedEvent Property
  13. /// <value>Identifies the RoutedEvent dependency property</value>
  14. public static readonly DependencyProperty RoutedEventProperty =
  15. DependencyProperty.Register("RoutedEvent", typeof(RoutedEvent), typeof(EventCommandTrigger),
  16. new FrameworkPropertyMetadata(null));
  17. /// <value>description for RoutedEvent property</value>
  18. public RoutedEvent RoutedEvent
  19. {
  20. get { return (RoutedEvent)GetValue(RoutedEventProperty); }
  21. set { SetValue(RoutedEventProperty, value); }
  22. }
  23. #endregion
  24. #endregion
  25. protected override Freezable CreateInstanceCore()
  26. {
  27. return new EventCommandTrigger();
  28. }
  29. protected override void InitializeCore(FrameworkElement source)
  30. {
  31. source.AddHandler(RoutedEvent, (RoutedEventHandler)ExecuteCommand);
  32. }
  33. private void ExecuteCommand(object sender, RoutedEventArgs args)
  34. {
  35. CommandParameter<object> parameter = new EventCommandParameter<object, RoutedEventArgs>(
  36. CustomParameter, RoutedEvent, args);
  37. base.ExecuteCommand(parameter);
  38. }
  39. }
  40. }