private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Effect effect = Effect; if (effect != null) { if (effect.IsActive) { return; } IAttachedObject attachedObject = (IAttachedObject)effect; if (attachedObject.AssociatedObject != this) { attachedObject.Detach(); attachedObject.Attach(this); effect.Target = (Image)GetTemplateChild("ImagePresenter"); } EffectDirection direction = _direction; _direction = _direction == EffectDirection.Forward ? EffectDirection.Reverse : EffectDirection.Forward; effect.PlayEffect(direction); } }
public static void TestIAttachedObject <T>(IAttachedObject attachedObject) where T : SysWindows.DependencyObject, new() { T generic = new T(); Rectangle rectangle = new Rectangle(); Assert.IsNull(attachedObject.AssociatedObject, "iAttachedObject.AssociatedObject == null"); attachedObject.Attach(generic); Assert.AreEqual(attachedObject.AssociatedObject, generic, "After attaching generic iAttachedObject.AssociatedObject should be generic"); try { attachedObject.Attach(generic); } catch { Assert.Fail("Unexpected exception thrown."); } Assert.AreEqual(attachedObject.AssociatedObject, generic, "iAttachedObject.AssociatedObject == generic"); try { attachedObject.Attach(rectangle); Assert.Fail("InvalidOperationException should be thrown when attempting to attach a new object."); } catch (InvalidOperationException) { } Assert.AreEqual(attachedObject.AssociatedObject, generic, "iAttachedObject.AssociatedObject == generic"); attachedObject.Detach(); Assert.IsNull(attachedObject.AssociatedObject, "iAttachedObject.AssociatedObject == null"); try { attachedObject.Detach(); } catch { Assert.Fail("Unexpected exception thrown."); } Assert.IsNull(attachedObject.AssociatedObject, "iAttachedObject.AssociatedObject == null"); attachedObject.Attach(rectangle); Assert.AreEqual(attachedObject.AssociatedObject, rectangle, "After attaching rectangle, AttachedObject.AssociatedObject should be rectangle"); attachedObject.Detach(); }
public static void TestConstraintOnAssociatedObject <T>(IAttachedObject attachedObject) where T : SysWindows.DependencyObject, new() { UniqueClass nonConstraintObject = new UniqueClass(); T constraintObject = new T(); Assert.IsNull(attachedObject.AssociatedObject, "attachedObject.AssociatedObject == null"); attachedObject.Attach(constraintObject); Assert.AreEqual(attachedObject.AssociatedObject, constraintObject, "After attaching satisfying constraint to attachedObject, attachedObject.AssociatedObject should be that constraint"); attachedObject.Detach(); Assert.IsNull(attachedObject.AssociatedObject, "After detaching, attachedObject.AssociatedObject should be null"); try { attachedObject.Attach(nonConstraintObject); Assert.Fail("Attaching an object that does not satisfy the constraint should have thrown an InvalidOperationException."); } catch (InvalidOperationException) { } }
public static void Attach (this NSObject target, IAttachedObject attachedObject) { attachedObject.Attach (target); }
public static void Attach(this NSObject target, IAttachedObject attachedObject) { attachedObject.Attach(target); }