EventCommandParameter.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Windows;
  3. namespace OpenSEMI.ClientBase.Command
  4. {
  5. public class EventCommandParameter<TCustomParameter, TEventArgs> : CommandParameter<TCustomParameter> where TEventArgs : RoutedEventArgs
  6. {
  7. public RoutedEvent RoutedEvent
  8. {
  9. get;
  10. private set;
  11. }
  12. public TEventArgs EventArgs
  13. {
  14. get;
  15. private set;
  16. }
  17. public EventCommandParameter(TCustomParameter customParameter, RoutedEvent routedEvent, TEventArgs eventArgs)
  18. : base(customParameter)
  19. {
  20. RoutedEvent = routedEvent;
  21. EventArgs = eventArgs;
  22. }
  23. public new static EventCommandParameter<TCustomParameter, TEventArgs> Cast(object parameter)
  24. {
  25. EventCommandParameter<object, RoutedEventArgs> eventCommandParameter = parameter as EventCommandParameter<object, RoutedEventArgs>;
  26. if (eventCommandParameter == null)
  27. {
  28. throw new InvalidCastException($"Failed to case {parameter.GetType()} to {typeof(EventCommandParameter<object, RoutedEventArgs>)}");
  29. }
  30. return new EventCommandParameter<TCustomParameter, TEventArgs>((TCustomParameter)eventCommandParameter.CustomParameter, eventCommandParameter.RoutedEvent, (TEventArgs)eventCommandParameter.EventArgs);
  31. }
  32. }
  33. }