public void TestBehaviorsAttachedDP() { var behavior = new MockBehavior <MockBindable> (); var bindable = new MockBindable(); var collection = bindable.Behaviors; Assert.Null(behavior.AssociatedObject); collection.Add(behavior); Assert.AreSame(bindable, behavior.AssociatedObject); collection.Remove(behavior); Assert.Null(behavior.AssociatedObject); }
public void BehaviorsAddedToAttachedCollectionAreAttached() { var behavior = new MockBehavior <MockBindable> (); var collection = new AttachedCollection <Behavior> (); var bindable = new MockBindable(); ((IAttachedObject)collection).AttachTo(bindable); Assert.Null(behavior.AssociatedObject); collection.Add(behavior); Assert.AreSame(bindable, behavior.AssociatedObject); collection.Remove(behavior); Assert.Null(behavior.AssociatedObject); }
public void TestTriggersAndBehaviors() { var behavior = new MockBehavior <Entry> (); var style = new Style(typeof(Entry)) { Setters = { new Setter { Property = Entry.TextProperty, Value = "foo" }, }, Triggers = { new Trigger(typeof(VisualElement)) { Property = Entry.IsPasswordProperty, Value = true, Setters = { new Setter { Property = VisualElement.ScaleProperty, Value = 2d }, } } }, Behaviors = { behavior, } }; var entry = new Entry { Style = style }; Assert.AreEqual("foo", entry.Text); Assert.AreEqual(1d, entry.Scale); entry.IsPassword = true; Assert.AreEqual(2d, entry.Scale); Assert.True(behavior.attached); entry.Style = null; Assert.AreEqual(Entry.TextProperty.DefaultValue, entry.Text); Assert.True(entry.IsPassword); Assert.AreEqual(1d, entry.Scale); Assert.True(behavior.detached); }
public void AttachAndDetach() { var behavior = new MockBehavior <MockBindable> (); var bindable = new MockBindable(); Assert.False(behavior.attached); Assert.False(behavior.detached); Assert.Null(behavior.AssociatedObject); ((IAttachedObject)behavior).AttachTo(bindable); Assert.True(behavior.attached); Assert.False(behavior.detached); Assert.AreSame(bindable, behavior.AssociatedObject); ((IAttachedObject)behavior).DetachFrom(bindable); Assert.True(behavior.attached); Assert.True(behavior.detached); Assert.Null(behavior.AssociatedObject); }