Exemplo n.º 1
0
        public void ChangingContentsOfNestedObservableCollectionUpdatesTreeMap()
        {
            TreeMap treeMap = new TreeMap();
            TreeMapItemDefinition itemDefinition = new TreeMapItemDefinition
            {
                ValueBinding = new Binding(),
                ItemsSource  = new Binding("Value"),
            };

            itemDefinition.ItemTemplate = (DataTemplate)XamlReader.Load(SimpleItemTemplate);
            treeMap.ItemDefinition      = itemDefinition;
            ObservableCollection <int> nestedItemsSourceA = new ObservableCollection <int>();
            ObservableCollection <int> nestedItemsSourceB = new ObservableCollection <int>();

            treeMap.ItemsSource = new KeyValuePair <int, ObservableCollection <int> >[]
            {
                new KeyValuePair <int, ObservableCollection <int> >(0, nestedItemsSourceA),
                new KeyValuePair <int, ObservableCollection <int> >(0, nestedItemsSourceB),
            };
            TestAsync(
                treeMap,
                // +1 because of the Border in default template
                () => Assert.AreEqual(0 + 2 + 1, treeMap.GetVisualDescendents().OfType <Border>().Count()),
                () => nestedItemsSourceA.Add(1),
                () => Assert.AreEqual(1 + 2 + 1, treeMap.GetVisualDescendents().OfType <Border>().Count()),
                () => nestedItemsSourceB.Add(2),
                () => Assert.AreEqual(2 + 2 + 1, treeMap.GetVisualDescendents().OfType <Border>().Count()),
                () => nestedItemsSourceA.Add(3),
                () => Assert.AreEqual(3 + 2 + 1, treeMap.GetVisualDescendents().OfType <Border>().Count()),
                () => nestedItemsSourceB.Clear(),
                () => Assert.AreEqual(2 + 2 + 1, treeMap.GetVisualDescendents().OfType <Border>().Count()),
                () => nestedItemsSourceA.Clear(),
                () => Assert.AreEqual(0 + 2 + 1, treeMap.GetVisualDescendents().OfType <Border>().Count()));
        }
        /// <summary>
        /// Exposes virtual protected for testing.
        /// </summary>
        /// <param name="oldValue">The old Value.</param>
        /// <param name="newValue">The new Value.</param>
        protected override void OnItemDefinitionPropertyChanged(TreeMapItemDefinition oldValue, TreeMapItemDefinition newValue)
        {
            base.OnItemDefinitionPropertyChanged(oldValue, newValue);

            if (OnItemDefinitionPropertyChangedEvent != null)
            {
                OnItemDefinitionPropertyChangedEvent(oldValue, newValue);
            }
        }
        public virtual void ValueChildItemPadding()
        {
            TreeMapItemDefinition testItemDef = new TreeMapItemDefinition();

            Assert.IsNotNull(testItemDef.ChildItemPadding);
            Assert.AreEqual(0, testItemDef.ChildItemPadding.Left);
            Assert.AreEqual(0, testItemDef.ChildItemPadding.Top);
            Assert.AreEqual(0, testItemDef.ChildItemPadding.Right);
            Assert.AreEqual(0, testItemDef.ChildItemPadding.Bottom);
        }
Exemplo n.º 4
0
        public void ChangingTreeMapItemDefinitionItemsSourceUpdatesTreeMap()
        {
            TreeMap treeMap = new TreeMap();
            TreeMapItemDefinition itemDefinition = new TreeMapItemDefinition {
                ValueBinding = new Binding()
            };

            itemDefinition.ItemTemplate = (DataTemplate)XamlReader.Load(SimpleItemTemplate);
            treeMap.ItemDefinition      = itemDefinition;
            treeMap.ItemsSource         = new KeyValuePair <int, int[]>[] { new KeyValuePair <int, int[]>(1, new int[] { 2, 3, 4, 5 }) };
            TestAsync(
                treeMap,
                // +1 because of the Border in default template
                () => Assert.AreEqual(1 + 1, treeMap.GetVisualDescendents().OfType <Border>().Count()),
                () => itemDefinition.ItemsSource = new Binding("Value"),
                () => Assert.AreEqual(5 + 1, treeMap.GetVisualDescendents().OfType <Border>().Count()));
        }
        public virtual void ValuePathTest()
        {
            const string          BindingName = "Foo";
            TreeMapItemDefinition testItemDef = new TreeMapItemDefinition();

            Assert.IsNull(testItemDef.ValueBinding);
            Assert.IsNull(testItemDef.ValuePath);

            testItemDef.ValuePath = BindingName;

            Assert.IsNotNull(testItemDef.ValueBinding);
            Assert.AreEqual(BindingName, testItemDef.ValueBinding.Path.Path);

            testItemDef.ValuePath = null;

            Assert.IsNull(testItemDef.ValueBinding);
            Assert.IsNull(testItemDef.ValuePath);
        }
        /// <summary>
        /// Returns an instance of a TreeMapItemDefinition class used to specify properties for the
        /// current item.
        /// </summary>
        /// <param name="treeMap">Reference to the TreeMap class.</param>
        /// <param name="item">One of the nodes in the ItemsSource hierarchy.</param>
        /// <param name="level">The level of the node in the hierarchy.</param>
        /// <returns>The TreeMapItemDefinition to be used for this node. If this method returns null
        /// the TreeMap will use the value of its ItemDefinition property.</returns>
        public override TreeMapItemDefinition SelectItemDefinition(TreeMap treeMap, object item, int level)
        {
            TreeMapItemDefinition template = null;

            switch (level)
            {
            case 0:
                template = Children[0];
                break;

            case 1:
                template = Children[1];
                break;

            default:
                template = Children[2];
                break;
            }

            return(template);
        }
Exemplo n.º 7
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);
        }