Пример #1
0
        public void TreeMapInheritViaProtectedVirtual()
        {
            InheritedTreeMap treeMap = new InheritedTreeMap();

            // Set initial values.
            TreeMapItemDefinitionSelector selectorOld = new SampleTemplateSelector();
            treeMap.SetValue(TreeMap.ItemDefinitionSelectorProperty, selectorOld);
            TreeMapItemDefinition definitionOld = new TreeMapItemDefinition { ChildItemPadding = new Thickness(0) };
            treeMap.SetValue(TreeMap.ItemDefinitionProperty, definitionOld);
            int[] itemsOld = new int[] { 1 };
            treeMap.SetValue(TreeMap.ItemsSourceProperty, itemsOld);
            Collection<Interpolator> collectionOld = new Collection<Interpolator> { new DoubleInterpolator() };
            treeMap.SetValue(TreeMap.InterpolatorsProperty, collectionOld);

            // Test TreeMapItemDefinitionSelectorProperty
            TreeMapItemDefinitionSelector selectorNew = new SampleTemplateSelector();
            bool calledItemDefinitionSelectorPropertyEvent = false;
            
            treeMap.OnItemDefinitionSelectorPropertyChangedEvent += (oldValue, newValue) =>
            {
                Assert.AreEqual(oldValue, selectorOld);
                Assert.AreEqual(newValue, selectorNew);
                Assert.AreNotEqual(newValue, oldValue);
                Assert.IsFalse(calledItemDefinitionSelectorPropertyEvent);
                calledItemDefinitionSelectorPropertyEvent = true;
            };
            treeMap.SetValue(TreeMap.ItemDefinitionSelectorProperty, selectorNew);
            Assert.IsTrue(calledItemDefinitionSelectorPropertyEvent);

            // Test ItemDefinitionProperty
            TreeMapItemDefinition definitionNew = new TreeMapItemDefinition { ChildItemPadding = new Thickness(1) };

            bool calledItemDefinitionPropertyyEvent = false;
            treeMap.OnItemDefinitionPropertyChangedEvent += (oldValue, newValue) =>
            {
                Assert.AreEqual(oldValue, definitionOld);
                Assert.AreEqual(newValue, definitionNew);
                Assert.AreNotEqual(newValue, oldValue);
                Assert.IsFalse(calledItemDefinitionPropertyyEvent);
                calledItemDefinitionPropertyyEvent = true;
            };
            treeMap.SetValue(TreeMap.ItemDefinitionProperty, definitionNew);
            Assert.IsTrue(calledItemDefinitionPropertyyEvent);

            // Test ItemsSourceProperty
            int[] itemsNew = new int[] { 1, 2, 3 };

            bool calledItemsSourceProperty = false;
            treeMap.OnItemsSourcePropertyChangedEvent += (oldValue, newValue) =>
            {
                Assert.AreEqual(oldValue, itemsOld);
                Assert.AreEqual(newValue, itemsNew);
                Assert.AreNotEqual(newValue, oldValue);
                Assert.AreNotEqual(newValue, oldValue);
                Assert.IsFalse(calledItemsSourceProperty);
                calledItemsSourceProperty = true;
            };
            treeMap.SetValue(TreeMap.ItemsSourceProperty, itemsNew);
            Assert.IsTrue(calledItemsSourceProperty);

            // Test InterpolatorsPropertyChanged
            Collection<Interpolator> collectionNew = new Collection<Interpolator> { new SolidColorBrushInterpolator() };

            bool calledOnInterpolatorsPropertyChangedEvent = false;
            treeMap.OnInterpolatorsPropertyChangedEvent += (oldValue, newValue) =>
            {
                Assert.AreEqual(oldValue, collectionOld);
                Assert.AreEqual(newValue, collectionNew);
                Assert.IsFalse(calledOnInterpolatorsPropertyChangedEvent);
                calledOnInterpolatorsPropertyChangedEvent = true;
            };
            treeMap.SetValue(TreeMap.InterpolatorsProperty, collectionNew);
            Assert.IsTrue(calledOnInterpolatorsPropertyChangedEvent);
        }
Пример #2
0
        public void TreeMapInheritViaProtectedVirtual()
        {
            InheritedTreeMap treeMap = new InheritedTreeMap();

            // Set initial values.
            TreeMapItemDefinitionSelector selectorOld = new SampleTemplateSelector();

            treeMap.SetValue(TreeMap.ItemDefinitionSelectorProperty, selectorOld);
            TreeMapItemDefinition definitionOld = new TreeMapItemDefinition {
                ChildItemPadding = new Thickness(0)
            };

            treeMap.SetValue(TreeMap.ItemDefinitionProperty, definitionOld);
            int[] itemsOld = new int[] { 1 };
            treeMap.SetValue(TreeMap.ItemsSourceProperty, itemsOld);
            Collection <Interpolator> collectionOld = new Collection <Interpolator> {
                new DoubleInterpolator()
            };

            treeMap.SetValue(TreeMap.InterpolatorsProperty, collectionOld);

            // Test TreeMapItemDefinitionSelectorProperty
            TreeMapItemDefinitionSelector selectorNew      = new SampleTemplateSelector();
            bool calledItemDefinitionSelectorPropertyEvent = false;

            treeMap.OnItemDefinitionSelectorPropertyChangedEvent += (oldValue, newValue) =>
            {
                Assert.AreEqual(oldValue, selectorOld);
                Assert.AreEqual(newValue, selectorNew);
                Assert.AreNotEqual(newValue, oldValue);
                Assert.IsFalse(calledItemDefinitionSelectorPropertyEvent);
                calledItemDefinitionSelectorPropertyEvent = true;
            };
            treeMap.SetValue(TreeMap.ItemDefinitionSelectorProperty, selectorNew);
            Assert.IsTrue(calledItemDefinitionSelectorPropertyEvent);

            // Test ItemDefinitionProperty
            TreeMapItemDefinition definitionNew = new TreeMapItemDefinition {
                ChildItemPadding = new Thickness(1)
            };

            bool calledItemDefinitionPropertyyEvent = false;

            treeMap.OnItemDefinitionPropertyChangedEvent += (oldValue, newValue) =>
            {
                Assert.AreEqual(oldValue, definitionOld);
                Assert.AreEqual(newValue, definitionNew);
                Assert.AreNotEqual(newValue, oldValue);
                Assert.IsFalse(calledItemDefinitionPropertyyEvent);
                calledItemDefinitionPropertyyEvent = true;
            };
            treeMap.SetValue(TreeMap.ItemDefinitionProperty, definitionNew);
            Assert.IsTrue(calledItemDefinitionPropertyyEvent);

            // Test ItemsSourceProperty
            int[] itemsNew = new int[] { 1, 2, 3 };

            bool calledItemsSourceProperty = false;

            treeMap.OnItemsSourcePropertyChangedEvent += (oldValue, newValue) =>
            {
                Assert.AreEqual(oldValue, itemsOld);
                Assert.AreEqual(newValue, itemsNew);
                Assert.AreNotEqual(newValue, oldValue);
                Assert.AreNotEqual(newValue, oldValue);
                Assert.IsFalse(calledItemsSourceProperty);
                calledItemsSourceProperty = true;
            };
            treeMap.SetValue(TreeMap.ItemsSourceProperty, itemsNew);
            Assert.IsTrue(calledItemsSourceProperty);

            // Test InterpolatorsPropertyChanged
            Collection <Interpolator> collectionNew = new Collection <Interpolator> {
                new SolidColorBrushInterpolator()
            };

            bool calledOnInterpolatorsPropertyChangedEvent = false;

            treeMap.OnInterpolatorsPropertyChangedEvent += (oldValue, newValue) =>
            {
                Assert.AreEqual(oldValue, collectionOld);
                Assert.AreEqual(newValue, collectionNew);
                Assert.IsFalse(calledOnInterpolatorsPropertyChangedEvent);
                calledOnInterpolatorsPropertyChangedEvent = true;
            };
            treeMap.SetValue(TreeMap.InterpolatorsProperty, collectionNew);
            Assert.IsTrue(calledOnInterpolatorsPropertyChangedEvent);
        }