TriggerActionCollection.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Windows;
  3. namespace HandyControl.Interactivity;
  4. public class TriggerActionCollection : AttachableCollection<TriggerAction>
  5. {
  6. internal TriggerActionCollection()
  7. {
  8. }
  9. protected override Freezable CreateInstanceCore()
  10. {
  11. return new TriggerActionCollection();
  12. }
  13. internal override void ItemAdded(TriggerAction item)
  14. {
  15. if (item.IsHosted)
  16. throw new InvalidOperationException(ExceptionStringTable
  17. .CannotHostTriggerActionMultipleTimesExceptionMessage);
  18. if (AssociatedObject != null)
  19. item.Attach(AssociatedObject);
  20. item.IsHosted = true;
  21. }
  22. internal override void ItemRemoved(TriggerAction item)
  23. {
  24. if (((IAttachedObject) item).AssociatedObject != null)
  25. item.Detach();
  26. item.IsHosted = false;
  27. }
  28. protected override void OnAttached()
  29. {
  30. foreach (var action in this)
  31. action.Attach(AssociatedObject);
  32. }
  33. protected override void OnDetaching()
  34. {
  35. foreach (var action in this)
  36. action.Detach();
  37. }
  38. }