/// <summary> /// Called when the value of the TreeMapItemDefinitionSelectorProperty property changes. /// </summary> /// <param name="d">Reference to the TreeMap object.</param> /// <param name="e">Event handler arguments.</param> private static void OnItemDefinitionSelectorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TreeMap treeMap = d as TreeMap; if (treeMap != null) { TreeMapItemDefinitionSelector oldValue = e.OldValue as TreeMapItemDefinitionSelector; TreeMapItemDefinitionSelector newValue = e.NewValue as TreeMapItemDefinitionSelector; treeMap.OnItemDefinitionSelectorPropertyChanged(oldValue, newValue); } }
/// <summary> /// Called when the value of the ItemsSourceProperty property changes. /// </summary> /// <param name="d">Reference to the TreeMap object.</param> /// <param name="e">Event handler arguments.</param> private static void OnItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TreeMap treeMap = d as TreeMap; if (treeMap != null) { IEnumerable oldValue = e.OldValue as IEnumerable; IEnumerable newValue = e.NewValue as IEnumerable; treeMap.OnItemsSourcePropertyChanged(oldValue, newValue); } }
/// <summary> /// Called when the value of the InterpolatorsProperty property changes. /// </summary> /// <param name="d">Reference to the TreeMap object.</param> /// <param name="e">Event handler arguments.</param> private static void OnInterpolatorsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TreeMap treeMap = d as TreeMap; if (treeMap != null) { Collection <Interpolator> oldValue = e.OldValue as Collection <Interpolator>; Collection <Interpolator> newValue = e.NewValue as Collection <Interpolator>; treeMap.OnInterpolatorsPropertyChanged(oldValue, newValue); } }
/// <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) { if (Children.Count > 0) { int child = level % Children.Count; return Children[child]; } else { return null; } }
/// <summary> /// Returns an instance of a SegmentItemDefinitionSelector 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) { SegmentNode node = item as SegmentNode; if (Children.Count > 0 && node != null && node.Segment >= 0) { int child = node.Segment % Children.Count; return Children[child]; } else { return null; } }
/// <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; }
/// <summary> /// Called when the value of the ItemDefinitionProperty property changes. /// </summary> /// <param name="d">Reference to the TreeMap object.</param> /// <param name="e">Event handler arguments.</param> private static void OnItemDefinitionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TreeMap treeMap = d as TreeMap; if (treeMap != null) { TreeMapItemDefinition oldValue = e.OldValue as TreeMapItemDefinition; TreeMapItemDefinition newValue = e.NewValue as TreeMapItemDefinition; // Unregister old TreeMapItemDefinition if (oldValue != null) { oldValue.PropertyChanged -= treeMap.OnItemDefinitionPropertyChanged; } // Register new TreeMapItemDefinition if (newValue != null) { newValue.PropertyChanged += treeMap.OnItemDefinitionPropertyChanged; } treeMap.OnItemDefinitionPropertyChanged(oldValue, newValue); } }
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())); }
/// <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 ItemTemplate property.</returns> public override TreeMapItemDefinition SelectItemDefinition(TreeMap treeMap, object item, int level) { throw new NotImplementedException(); }
/// <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 abstract TreeMapItemDefinition SelectItemDefinition(TreeMap treeMap, object item, int level);
public void TreeMapInHorizontalStackPanelHasMinWidth() { TreeMap treeMap = new TreeMap(); StackPanel panel = new StackPanel { Width = 100, Height = 200, Orientation = Orientation.Horizontal }; panel.Children.Add(treeMap); TestAsync( panel, () => Assert.AreEqual(treeMap.MinWidth, treeMap.ActualWidth), () => Assert.AreEqual(panel.ActualHeight, treeMap.ActualHeight)); }
public void TreeMapInGridIsFullSize() { TreeMap treeMap = new TreeMap(); Grid panel = new Grid { Width = 100, Height = 200 }; panel.Children.Add(treeMap); TestAsync( panel, () => Assert.AreEqual(panel.ActualWidth, treeMap.ActualWidth), () => Assert.AreEqual(panel.ActualHeight, treeMap.ActualHeight)); }
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())); }
public void ChangingContentsOfObservableCollectionUpdatesTreeMap() { TreeMap treeMap = new TreeMap(); ObservableCollection<int> itemsSource = new ObservableCollection<int>(); treeMap.ItemsSource = itemsSource; TestAsync( treeMap, // +1 because of the Border in default template () => Assert.AreEqual(0 + 1, treeMap.GetVisualDescendents().OfType<Border>().Count()), () => itemsSource.Add(1), () => Assert.AreEqual(1 + 1, treeMap.GetVisualDescendents().OfType<Border>().Count()), () => itemsSource.Add(1), () => Assert.AreEqual(2 + 1, treeMap.GetVisualDescendents().OfType<Border>().Count()), () => itemsSource.Clear(), () => Assert.AreEqual(0 + 1, treeMap.GetVisualDescendents().OfType<Border>().Count())); }
public void ClearingItemsSourceRemovesChildren() { TreeMap treeMap = new TreeMap(); TestAsync( treeMap, // +1 because of the Border in default template () => Assert.AreEqual(0 + 1, treeMap.GetVisualDescendents().OfType<Border>().Count()), () => treeMap.ItemsSource = new int[] { 1, 2, 3 }, () => Assert.AreEqual(3 + 1, treeMap.GetVisualDescendents().OfType<Border>().Count()), () => treeMap.ItemsSource = null, () => Assert.AreEqual(0 + 1, treeMap.GetVisualDescendents().OfType<Border>().Count())); }
public void TreeMapRendersSimpleData() { TreeMap treeMap = new TreeMap(); treeMap.ItemsSource = new int[] { 1, 2, 3 }; TestAsync( treeMap, // +1 because of the Border in default template () => Assert.AreEqual(3 + 1, treeMap.GetVisualDescendents().OfType<Border>().Count())); }
public void ProvidingNullTreeMapItemDefinitionItemTemplateWorks() { TreeMap treeMap = new TreeMap(); treeMap.ItemDefinition = new TreeMapItemDefinition { ValueBinding = new Binding() }; TestAsync( treeMap, // +1 because of the Border in default template () => treeMap.ItemsSource = new int[] { 1, 2, 3 }, () => Assert.AreEqual(0 + 1, treeMap.GetVisualDescendents().OfType<Border>().Count())); }