public void TreeViewItemContainerTransitionTest()
 {
     RunOnUIThread.Execute(() =>
     {
         TreeView treeView = new TreeView();
         treeView.Loaded  += (object sender, RoutedEventArgs e) =>
         {
             var transition = (TransitionCollection)XamlReader.Load(
                 @"<TransitionCollection xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> 
                     <ContentThemeTransition />
               </TransitionCollection>");
             treeView.ItemContainerTransitions = transition;
             var node = new TreeViewNode();
             treeView.RootNodes.Add(node);
             var listControl  = FindVisualChildByName(treeView, "ListControl") as TreeViewList;
             var treeViewItem = listControl.ContainerFromItem(node) as TreeViewItem;
             Verify.AreEqual(treeViewItem.ContentTransitions, transition);
         };
     });
 }
Beispiel #2
0
        public void VerifyVisualTree()
        {
            TreeView treeView = null;

            RunOnUIThread.Execute(() =>
            {
                treeView = new TreeView()
                {
                    Width = 400, Height = 400
                };
                var node1 = new TreeViewNode()
                {
                    Content = "Node1"
                };
                treeView.RootNodes.Add(node1);
            });
            TestUtilities.SetAsVisualTreeRoot(treeView);

            VisualTreeTestHelper.VerifyVisualTree(root: treeView, verificationFileNamePrefix: "TreeView");
        }
Beispiel #3
0
 public void TreeViewItemTemplateTest()
 {
     RunOnUIThread.Execute(() =>
     {
         TreeView treeView = new TreeView();
         treeView.Loaded  += (object sender, RoutedEventArgs e) =>
         {
             var dataTemplate = (DataTemplate)XamlReader.Load(
                 @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> 
                   <TextBlock Text='TreeViewItemTemplate'/>
               </DataTemplate>");
             treeView.ItemTemplate = dataTemplate;
             var node = new TreeViewNode();
             treeView.RootNodes.Add(node);
             var listControl  = FindVisualChildByName(treeView, "ListControl") as TreeViewList;
             var treeViewItem = listControl.ContainerFromItem(node) as TreeViewItem;
             Verify.AreEqual(treeViewItem.ContentTemplate, dataTemplate);
         };
     });
 }
Beispiel #4
0
        private void GetRootNodeChildrenOrder(TreeView tree)
        {
            StringBuilder        sb           = new StringBuilder();
            Stack <TreeViewNode> pendingNodes = new Stack <TreeViewNode>();

            pendingNodes.Push(tree.RootNodes[0]);
            while (pendingNodes.Count > 0)
            {
                var currentNode = pendingNodes.Pop();
                var children    = currentNode.Children;
                var size        = children.Count;
                for (int i = 0; i < size; i++)
                {
                    pendingNodes.Push(currentNode.Children[size - 1 - i]);
                }
                sb.Append(GetNodeContent(currentNode) + " | ");
            }

            Results.Text = sb.ToString();
        }
Beispiel #5
0
        private string GetRootNodeChildrenOrder(TreeView tree)
        {
            List <string>        result       = new List <string>();
            Stack <TreeViewNode> pendingNodes = new Stack <TreeViewNode>();

            pendingNodes.Push(tree.RootNodes[0]);
            while (pendingNodes.Count > 0)
            {
                var currentNode = pendingNodes.Pop();
                var size        = currentNode.Children.Count;
                for (int i = 0; i < size; i++)
                {
                    pendingNodes.Push(currentNode.Children[size - 1 - i]);
                }

                result.Add(GetNodeContent(currentNode));
            }

            return(string.Join(" | ", result));
        }
Beispiel #6
0
 public void TreeViewItemContainerStyleTest()
 {
     RunOnUIThread.Execute(() =>
     {
         TreeView treeView = new TreeView();
         treeView.Loaded  += (object sender, RoutedEventArgs e) =>
         {
             var style = (Style)XamlReader.Load(
                 @"<Style xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> 
                   <Setter Property='Background' Value='Green'/>
               </Style>");
             treeView.ItemContainerStyle = style;
             var node = new TreeViewNode();
             treeView.RootNodes.Add(node);
             var listControl  = FindVisualChildByName(treeView, "ListControl") as TreeViewList;
             var treeViewItem = listControl.ContainerFromItem(node) as TreeViewItem;
             Verify.AreEqual(treeViewItem.Style, style);
         };
     });
 }
Beispiel #7
0
        public void TreeViewBackgroundTest()
        {
            RunOnUIThread.Execute(() =>
            {
                var treeView = new TreeView();

                Content = treeView;
                Content.UpdateLayout();

                var treeViewList = VisualTreeUtils.FindVisualChildByName(treeView, "ListControl") as TreeViewList;

                // Make sure the TreeViewList does not already have the background color we are using for this test.
                bool testCondition = treeViewList.Background is SolidColorBrush brush && brush.Color == Colors.Green;
                Verify.IsFalse(testCondition, "The default TreeView background color should not match the test color used.");

                // Check if the Background API affects the TreeView control.
                treeView.Background = new SolidColorBrush(Colors.Green);
                Content.UpdateLayout();

                testCondition = treeViewList.Background is SolidColorBrush brush2 && brush2.Color == Colors.Green;
                Verify.IsTrue(testCondition, "The TreeView background UI should have matched the specified test color.");
            });
        }
        private String GetRootNodeChildrenOrder(TreeView tree)
        {
            StringBuilder        sb           = new StringBuilder();
            Stack <TreeViewNode> pendingNodes = new Stack <TreeViewNode>();

            pendingNodes.Push(tree.RootNodes[0]);
            while (pendingNodes.Count > 0)
            {
                var currentNode = pendingNodes.Pop();
                var size        = currentNode.Children.Count;
                for (int i = 0; i < size; i++)
                {
                    pendingNodes.Push(currentNode.Children[size - 1 - i]);
                }
                if (sb.Length > 0)
                {
                    sb.Append(" | ");
                }
                sb.Append(GetNodeContent(currentNode));
            }

            return(sb.ToString());
        }
Beispiel #9
0
        private void TestTreeView_Expanding(TreeView sender, TreeViewExpandingEventArgs args)
        {
            var loadingNode = args.Node;

            if (loadingNode == _virtualizedNode)
            {
                loadingNode.Children.Add(new TreeViewNode()
                {
                    Content = "Loaded: 1"
                });
                loadingNode.Children.Add(new TreeViewNode()
                {
                    Content = "Loaded: 2"
                });
                loadingNode.Children.Add(new TreeViewNode()
                {
                    Content = "Loaded: 3"
                });
                loadingNode.HasUnrealizedChildren = false;

                Results.Text = "Loaded";
            }
        }
Beispiel #10
0
        private string GetSelection(TreeView tree)
        {
            int count = tree.SelectedNodes.Count;

            if (count != tree.SelectedItems.Count)
            {
                return("SelectedNodes.Count != SelectedItems.Count");
            }

            List <string> result = new List <string>();

            for (int i = 0; i < count; i++)
            {
                // Make sure selectedNodes and SelectedItems are in sync
                var node = tree.SelectedNodes[i];
                var item = IsInContentMode() ? node.Content : node;
                if (item != tree.SelectedItems[i])
                {
                    return("$SelectedNodes[{i}] != SelectedItems[{i}]");
                }

                result.Add(GetNodeContent(node));
            }

            result.Sort();

            // Verify SelectedItem and SelectedNode for single selection
            if (tree.SelectionMode == TreeViewSelectionMode.Single && result.Count > 0)
            {
                if (tree.SelectedItem != tree.SelectedItems[0] || tree.SelectedNode != tree.SelectedNodes[0])
                {
                    return("SelectedItem!=SelectedItems[0] || SelectedNode!=SelectedNodes[0]");
                }
            }

            return(result.Count > 0 ? "Selected: " + string.Join(", ", result) : "Nothing selected");
        }
Beispiel #11
0
        public void TreeViewItemsSourceUpdateTest()
        {
            var treeView = new TreeView();
            var items    = CreateTreeViewItemsSource();

            treeView.ItemsSource = items;

            // Insert
            var newItem = new TreeViewItemSource()
            {
                Content = "newItem"
            };

            items.Add(newItem);
            Verify.AreEqual(treeView.RootNodes.Count, 3);
            var itemFromNode = treeView.RootNodes[2].Content as TreeViewItemSource;

            Verify.AreEqual(newItem.Content, itemFromNode.Content);

            // Remove
            items.Remove(newItem);
            Verify.AreEqual(treeView.RootNodes.Count, 2);

            // Replace
            var item3 = new TreeViewItemSource()
            {
                Content = "3"
            };

            items[1]     = item3;
            itemFromNode = treeView.RootNodes[1].Content as TreeViewItemSource;
            Verify.AreEqual(item3.Content, itemFromNode.Content);

            // Clear
            items.Clear();
            Verify.AreEqual(treeView.RootNodes.Count, 0);
        }
Beispiel #12
0
        private void GetCheckBoxStates(TreeView tree)
        {
            StringBuilder        sb           = new StringBuilder();
            Stack <TreeViewNode> pendingNodes = new Stack <TreeViewNode>();

            pendingNodes.Push(tree.RootNodes[0]);
            while (pendingNodes.Count > 0)
            {
                var currentNode = pendingNodes.Pop();
                var children    = currentNode.Children;
                var size        = children.Count;
                for (int i = 0; i < size; i++)
                {
                    pendingNodes.Push(currentNode.Children[size - 1 - i]);
                }
                var treeViewItem = tree.ContainerFromNode(currentNode) as TreeViewItem;
                var checkBox     = FindVisualChildByName(treeViewItem, "MultiSelectCheckBox") as CheckBox;
                if (checkBox.IsChecked == true)
                {
                    // selected
                    sb.Append("s|");
                }
                else if (checkBox.IsChecked == false)
                {
                    // unselected
                    sb.Append("u|");
                }
                else
                {
                    // partial selected
                    sb.Append("p|");
                }
            }

            Results.Text = sb.ToString();
        }
Beispiel #13
0
        private void SetAutomationIdForNodes(TreeView tree)
        {
            var listControl = FindVisualChildByName(this.TestTreeView, "ListControl") as TreeViewList;
            Stack <TreeViewNode> pendingNodes = new Stack <TreeViewNode>();

            foreach (var node in tree.RootNodes)
            {
                pendingNodes.Push(node);
            }
            while (pendingNodes.Count > 0)
            {
                var currentNode = pendingNodes.Pop();
                foreach (var child in currentNode.Children)
                {
                    pendingNodes.Push(child);
                }

                var container = tree.ContainerFromNode(currentNode);
                if (container != null)
                {
                    AutomationProperties.SetAutomationId(container as DependencyObject, GetNodeContent(currentNode));
                }
            }
        }
Beispiel #14
0
        private String GetSelection(TreeView tree)
        {
            String result = "";

            if (TestTreeView.SelectionMode == TreeViewSelectionMode.Single)
            {
                var listControl = FindVisualChildByName(tree, "ListControl") as TreeViewList;
                if (IsInContentMode())
                {
                    result = "ItemSelected:" + ((TreeViewItemSource)listControl.SelectedItem).Content;
                }
                else
                {
                    result = "ItemSelected:" + ((TreeViewNode)listControl.SelectedItem).Content.ToString();
                }
            }
            else if (TestTreeView.SelectionMode == TreeViewSelectionMode.Multiple)
            {
                var items = tree.SelectedNodes;
                int count = items.Count;
                result = "Num. Selected: " + count;
            }
            return(result);
        }
Beispiel #15
0
        private void ContentModeTestTreeView_Expanding(TreeView sender, TreeViewExpandingEventArgs args)
        {
            var loadingItem = args.Item as TreeViewItemSource;
            var count       = TestTreeViewItemsSource[0].Children.Count;

            if (loadingItem == TestTreeViewItemsSource[0].Children[count - 1])
            {
                loadingItem.Children.Add(new TreeViewItemSource()
                {
                    Content = "Loaded: 1"
                });
                loadingItem.Children.Add(new TreeViewItemSource()
                {
                    Content = "Loaded: 2"
                });
                loadingItem.Children.Add(new TreeViewItemSource()
                {
                    Content = "Loaded: 3"
                });
                loadingItem.HasUnrealizedChildren = false;

                Results.Text = "Loaded";
            }
        }
Beispiel #16
0
        public void TreeViewUpdateTest()
        {
            TreeView     treeView      = null;
            TreeViewList listControl   = null;
            TreeViewNode treeViewNode1 = null;
            TreeViewNode treeViewNode2 = null;
            TreeViewNode treeViewNode3 = null;
            TreeViewNode treeViewNode4 = null;
            TreeViewNode treeViewNode5 = null;

            var loadedWaiter = new ManualResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                treeViewNode1 = new TreeViewNode();
                treeViewNode2 = new TreeViewNode();
                treeViewNode3 = new TreeViewNode();
                treeViewNode4 = new TreeViewNode();
                treeViewNode5 = new TreeViewNode();

                treeViewNode1.Children.Add(treeViewNode2);
                treeViewNode1.Children.Add(treeViewNode3);
                treeViewNode1.Children.Add(treeViewNode4);
                treeViewNode1.Children.Add(treeViewNode5);

                treeView = new TreeView();

                treeView.Loaded += (object sender, RoutedEventArgs e) =>
                {
                    listControl = FindVisualChildByName(treeView, "ListControl") as TreeViewList;
                    loadedWaiter.Set();
                };

                MUXControlsTestApp.App.TestContentRoot = treeView;
            });

            Verify.IsTrue(loadedWaiter.WaitOne(TimeSpan.FromMinutes(1)), "Check if Loaded was successfully raised");
            RunOnUIThread.Execute(() =>
            {
                treeView.RootNodes.Add(treeViewNode1);
                Verify.AreEqual(listControl.Items.Count, 1);

                treeView.Expand(treeViewNode1);
                Verify.AreEqual(listControl.Items.Count, 5);

                treeViewNode1.Children.RemoveAt(2);
                Verify.AreEqual(listControl.Items.Count, 4);
                Verify.AreEqual(listControl.Items[0], treeViewNode1);
                Verify.AreEqual(listControl.Items[1], treeViewNode2);
                Verify.AreEqual(listControl.Items[2], treeViewNode3);
                Verify.AreEqual(listControl.Items[3], treeViewNode5);

                treeViewNode1.Children.Insert(1, treeViewNode4);
                Verify.AreEqual(listControl.Items.Count, 5);
                Verify.AreEqual(listControl.Items[0], treeViewNode1);
                Verify.AreEqual(listControl.Items[1], treeViewNode2);
                Verify.AreEqual(listControl.Items[2], treeViewNode4);
                Verify.AreEqual(listControl.Items[3], treeViewNode3);
                Verify.AreEqual(listControl.Items[4], treeViewNode5);

                treeViewNode1.Children.Clear();
                Verify.AreEqual(listControl.Items.Count, 1);
                Verify.AreEqual(listControl.Items[0], treeViewNode1);

                // Put things back
                MUXControlsTestApp.App.TestContentRoot = null;
            });
        }
Beispiel #17
0
        public void TreeViewClearAndSetAtTest()
        {
            TreeView     treeView    = null;
            TreeViewList listControl = null;

            var loadedWaiter = new ManualResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                treeView         = new TreeView();
                treeView.Loaded += (object sender, RoutedEventArgs e) =>
                {
                    listControl = FindVisualChildByName(treeView, "ListControl") as TreeViewList;
                    loadedWaiter.Set();
                };

                MUXControlsTestApp.App.TestContentRoot = treeView;
            });

            Verify.IsTrue(loadedWaiter.WaitOne(TimeSpan.FromMinutes(1)), "Check if Loaded was successfully raised");
            RunOnUIThread.Execute(() =>
            {
                // Verify TreeViewNode::SetAt
                TreeViewNode setAtChildCheckNode = new TreeViewNode()
                {
                    Content = "Set At Child"
                };
                TreeViewNode setAtRootCheckNode = new TreeViewNode()
                {
                    Content = "Set At Root"
                };

                TreeViewNode child1 = new TreeViewNode()
                {
                    Content = "Child 1"
                };
                child1.Children.Add(new TreeViewNode()
                {
                    Content = "Child 1:1"
                });

                TreeViewNode child2 = new TreeViewNode()
                {
                    Content = "Child 2"
                };
                child2.Children.Add(new TreeViewNode()
                {
                    Content = "Child 2:1"
                });
                child2.Children.Add(new TreeViewNode()
                {
                    Content = "Child 2:2"
                });

                treeView.RootNodes.Add(child1);
                child1.IsExpanded = true;
                treeView.RootNodes.Add(child2);
                Verify.AreEqual(listControl.Items.Count, 3);

                // SetAt node under child node which is not expanded
                child2.Children[1] = setAtChildCheckNode;
                Verify.AreEqual(listControl.Items.Count, 3);

                // SetAt node under root node and child2 is expanded
                treeView.RootNodes[0] = setAtRootCheckNode;
                child2.IsExpanded     = true;
                Verify.AreEqual(listControl.Items.Count, 4);

                // Verify RootNode.Clear
                treeView.RootNodes.Clear();
                Verify.AreEqual(listControl.Items.Count, 0);

                // test clear without any child node
                treeView.RootNodes.Clear();
                Verify.AreEqual(listControl.Items.Count, 0);

                // Put things back
                MUXControlsTestApp.App.TestContentRoot = null;
            });
        }
Beispiel #18
0
        public async Task TreeViewSelectionChangedMultipleMode()
        {
            // input data:
            // - 1
            //   - 11
            //   - 12
            //   - 13
            // - 2
            //   - 21
            // - 3
            TreeView     treeView = null;
            TreeViewNode node1    = null;
            TreeViewNode node11   = null;
            TreeViewNode node12   = null;
            TreeViewNode node13   = null;
            TreeViewNode node2    = null;
            TreeViewNode node21   = null;
            TreeViewNode node3    = null;
            TreeViewSelectionChangedEventArgs selectionChangedEventArgs = null;
            await RunOnUIThread.ExecuteAsync(() =>
            {
                treeView = new TreeView {
                    SelectionMode = TreeViewSelectionMode.Multiple
                };
                treeView.SelectionChanged += (s, e) => selectionChangedEventArgs = e;

                node1 = new TreeViewNode {
                    Content = "1", IsExpanded = true
                };
                node11 = new TreeViewNode {
                    Content = "11"
                };
                node12 = new TreeViewNode {
                    Content = "12"
                };
                node13 = new TreeViewNode {
                    Content = "13"
                };
                node1.Children.Add(node11);
                node1.Children.Add(node12);
                node1.Children.Add(node13);

                node2 = new TreeViewNode {
                    Content = "2", IsExpanded = true
                };
                node21 = new TreeViewNode {
                    Content = "21"
                };
                node2.Children.Add(node21);

                node3 = new TreeViewNode {
                    Content = "3"
                };

                treeView.RootNodes.Add(node1);
                treeView.RootNodes.Add(node2);
                treeView.RootNodes.Add(node3);
                TestServices.WindowHelper.WindowContent = treeView;
            });

            await TestServices.WindowHelper.WaitForIdle();

            await RunOnUIThread.ExecuteAsync(() =>
            {
                var tvi1  = (TreeViewItem)treeView.ContainerFromItem(node1);
                var tvi11 = (TreeViewItem)treeView.ContainerFromItem(node11);
                var tvi12 = (TreeViewItem)treeView.ContainerFromItem(node12);
                var tvi13 = (TreeViewItem)treeView.ContainerFromItem(node13);
                var tvi2  = (TreeViewItem)treeView.ContainerFromItem(node2);
                var tvi21 = (TreeViewItem)treeView.ContainerFromItem(node21);
                var tvi3  = (TreeViewItem)treeView.ContainerFromItem(node3);

                // - 1         selected
                //   - 11      selected
                //   - 12      selected
                //   - 13      selected
                // - 2
                //   - 21
                // - 3
                tvi1.IsSelected = true;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(4, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node1));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node11));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node12));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node13));
                Verify.AreEqual(0, selectionChangedEventArgs.RemovedItems.Count);
                selectionChangedEventArgs = null;

                // - 1         selected
                //   - 11
                //   - 12      selected
                //   - 13      selected
                // - 2
                //   - 21
                // - 3
                tvi11.IsSelected = true;
                tvi11.IsSelected = false;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(0, selectionChangedEventArgs.AddedItems.Count);
                Verify.AreEqual(1, selectionChangedEventArgs.RemovedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.RemovedItems.Contains(node11));
                selectionChangedEventArgs = null;

                // - 1         selected
                //   - 11      selected
                //   - 12      selected
                //   - 13      selected
                // - 2         selected
                //   - 21      selected
                // - 3         selected
                treeView.SelectAll();
                Verify.IsNotNull(selectionChangedEventArgs);
                var items = selectionChangedEventArgs.AddedItems.ToList();
                Verify.AreEqual(7, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node1));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node11));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node12));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node13));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node2));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node21));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node3));
                Verify.AreEqual(0, selectionChangedEventArgs.RemovedItems.Count);
            });
        }
Beispiel #19
0
        public async Task TreeViewSelectionChangedSingleMode()
        {
            TreeView treeView = null;
            TreeViewSelectionChangedEventArgs selectionChangedEventArgs = null;

            await RunOnUIThread.ExecuteAsync(() =>
            {
                // input data:
                // - 1
                // - 2
                // - 3

                treeView = new TreeView {
                    SelectionMode = TreeViewSelectionMode.Single
                };
                treeView.SelectionChanged += (s, e1) => selectionChangedEventArgs = e1;

                var collection = new ObservableCollection <int> {
                    1, 2, 3
                };
                treeView.ItemsSource = collection;

                TestServices.WindowHelper.WindowContent = treeView;
            });

            await TestServices.WindowHelper.WaitForIdle();

            await RunOnUIThread.ExecuteAsync(() =>
            {
                var tvi1 = (TreeViewItem)treeView.ContainerFromItem(1);
                var tvi2 = (TreeViewItem)treeView.ContainerFromItem(2);

                tvi1.IsSelected = true;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(1, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(1));
                Verify.AreEqual(0, selectionChangedEventArgs.RemovedItems.Count);
                selectionChangedEventArgs = null;

                tvi2.IsSelected = true;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(1, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(2));
                Verify.AreEqual(1, selectionChangedEventArgs.RemovedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.RemovedItems.Contains(1));
                selectionChangedEventArgs = null;

                tvi2.IsSelected = false;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(0, selectionChangedEventArgs.AddedItems.Count);
                Verify.AreEqual(1, selectionChangedEventArgs.RemovedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.RemovedItems.Contains(2));
                selectionChangedEventArgs = null;

                tvi1.IsSelected = true;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(1, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(1));
                Verify.AreEqual(0, selectionChangedEventArgs.RemovedItems.Count);
                selectionChangedEventArgs = null;

                treeView.ItemsSource = null;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(0, selectionChangedEventArgs.AddedItems.Count);
                Verify.AreEqual(1, selectionChangedEventArgs.RemovedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.RemovedItems.Contains(1));
            });
        }
Beispiel #20
0
        public async Task TreeViewClearAndSetAtTest()
        {
            TreeView treeView = null;

            await RunOnUIThread.ExecuteAsync(() =>
            {
                treeView = new TreeView();

                TestServices.WindowHelper.WindowContent = treeView;
            });

            await TestServices.WindowHelper.WaitForIdle();

            await RunOnUIThread.ExecuteAsync(() =>
            {
                var listControl = FindVisualChildByName(treeView, "ListControl") as TreeViewList;
                // Verify TreeViewNode::SetAt
                TreeViewNode setAtChildCheckNode = new TreeViewNode()
                {
                    Content = "Set At Child"
                };
                TreeViewNode setAtRootCheckNode = new TreeViewNode()
                {
                    Content = "Set At Root"
                };

                TreeViewNode child1 = new TreeViewNode()
                {
                    Content = "Child 1"
                };
                child1.Children.Add(new TreeViewNode()
                {
                    Content = "Child 1:1"
                });

                TreeViewNode child2 = new TreeViewNode()
                {
                    Content = "Child 2"
                };
                child2.Children.Add(new TreeViewNode()
                {
                    Content = "Child 2:1"
                });
                child2.Children.Add(new TreeViewNode()
                {
                    Content = "Child 2:2"
                });

                treeView.RootNodes.Add(child1);
                child1.IsExpanded = true;
                treeView.RootNodes.Add(child2);
                Verify.AreEqual(listControl.GetItems()?.Count(), 3);

                // SetAt node under child node which is not expanded
                child2.Children[1] = setAtChildCheckNode;
                Verify.AreEqual(listControl.GetItems()?.Count(), 3);

                // SetAt node under root node and child2 is expanded
                treeView.RootNodes[0] = setAtRootCheckNode;
                child2.IsExpanded     = true;
                Verify.AreEqual(listControl.GetItems()?.Count(), 4);

                // Verify RootNode.Clear
                treeView.RootNodes.Clear();
                Verify.AreEqual(listControl.GetItems()?.Count(), 0);

                // test clear without any child node
                treeView.RootNodes.Clear();
                Verify.AreEqual(listControl.GetItems()?.Count(), 0);
            });

            await TestServices.WindowHelper.WaitForIdle();
        }
Beispiel #21
0
 /// <summary>
 /// Private method to do the work of UNselecting all treeview nodes.
 /// </summary>
 private void DeselectAllNodes(TreeView treeView)
 {
     treeView.SelectedNodes.Clear();
 }
 private void treeView_DragItemsCompleted(Microsoft.UI.Xaml.Controls.TreeView sender, Microsoft.UI.Xaml.Controls.TreeViewDragItemsCompletedEventArgs args)
 {
     ViewModel.FixNodes();
 }
Beispiel #23
0
 private void DragItemsCompletedForApiTest(TreeView sender, TreeViewDragItemsCompletedEventArgs args)
 {
     Results.Text += "->DragItemsCompleted:" + GetDraggedItemsNames(args.Items);
 }
Beispiel #24
0
 private void propTreeView_SelectionChanged(Microsoft.UI.Xaml.Controls.TreeView sender, Microsoft.UI.Xaml.Controls.TreeViewSelectionChangedEventArgs args)
 {
     UpdateSelection();
 }
Beispiel #25
0
        public void TreeViewClearAndSetAtTest()
        {
            RunOnUIThread.Execute(() =>
            {
                var treeView = new TreeView();

                Content = treeView;
                Content.UpdateLayout();
                var listControl = FindVisualChildByName(treeView, "ListControl") as TreeViewList;
                // Verify TreeViewNode::SetAt
                TreeViewNode setAtChildCheckNode = new TreeViewNode()
                {
                    Content = "Set At Child"
                };
                TreeViewNode setAtRootCheckNode = new TreeViewNode()
                {
                    Content = "Set At Root"
                };

                TreeViewNode child1 = new TreeViewNode()
                {
                    Content = "Child 1"
                };
                child1.Children.Add(new TreeViewNode()
                {
                    Content = "Child 1:1"
                });

                TreeViewNode child2 = new TreeViewNode()
                {
                    Content = "Child 2"
                };
                child2.Children.Add(new TreeViewNode()
                {
                    Content = "Child 2:1"
                });
                child2.Children.Add(new TreeViewNode()
                {
                    Content = "Child 2:2"
                });

                treeView.RootNodes.Add(child1);
                child1.IsExpanded = true;
                treeView.RootNodes.Add(child2);
                Verify.AreEqual(listControl.Items.Count, 3);

                // SetAt node under child node which is not expanded
                child2.Children[1] = setAtChildCheckNode;
                Verify.AreEqual(listControl.Items.Count, 3);

                // SetAt node under root node and child2 is expanded
                treeView.RootNodes[0] = setAtRootCheckNode;
                child2.IsExpanded     = true;
                Verify.AreEqual(listControl.Items.Count, 4);

                // Verify RootNode.Clear
                treeView.RootNodes.Clear();
                Verify.AreEqual(listControl.Items.Count, 0);

                // test clear without any child node
                treeView.RootNodes.Clear();
                Verify.AreEqual(listControl.Items.Count, 0);
            });
        }
Beispiel #26
0
 private void DragItemsStartingForApiTest(TreeView sender, TreeViewDragItemsStartingEventArgs args)
 {
     Results.Text = "DragItemsStarting:" + GetDraggedItemsNames(args.Items);
 }
Beispiel #27
0
        public void TreeViewSelectionChangedSingleMode()
        {
            RunOnUIThread.Execute(() =>
            {
                // input data:
                // - 1
                // - 2
                // - 3
                TreeViewSelectionChangedEventArgs selectionChangedEventArgs = null;

                var treeView = new TreeView {
                    SelectionMode = TreeViewSelectionMode.Single
                };
                treeView.SelectionChanged += (s, e1) => selectionChangedEventArgs = e1;

                var collection = new ObservableCollection <int> {
                    1, 2, 3
                };
                treeView.ItemsSource = collection;
                Content = treeView;
                Content.UpdateLayout();
                var tvi1 = (TreeViewItem)treeView.ContainerFromItem(1);
                var tvi2 = (TreeViewItem)treeView.ContainerFromItem(2);

                tvi1.IsSelected = true;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(1, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(1));
                Verify.AreEqual(0, selectionChangedEventArgs.RemovedItems.Count);
                selectionChangedEventArgs = null;

                tvi2.IsSelected = true;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(1, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(2));
                Verify.AreEqual(1, selectionChangedEventArgs.RemovedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.RemovedItems.Contains(1));
                selectionChangedEventArgs = null;

                tvi2.IsSelected = false;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(0, selectionChangedEventArgs.AddedItems.Count);
                Verify.AreEqual(1, selectionChangedEventArgs.RemovedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.RemovedItems.Contains(2));
                selectionChangedEventArgs = null;

                tvi1.IsSelected = true;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(1, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(1));
                Verify.AreEqual(0, selectionChangedEventArgs.RemovedItems.Count);
                selectionChangedEventArgs = null;

                treeView.ItemsSource = null;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(0, selectionChangedEventArgs.AddedItems.Count);
                Verify.AreEqual(1, selectionChangedEventArgs.RemovedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.RemovedItems.Contains(1));
            });
        }
Beispiel #28
0
        public void TreeViewSelectionChangedMultipleMode()
        {
            RunOnUIThread.Execute(() =>
            {
                // input data:
                // - 1
                //   - 11
                //   - 12
                //   - 13
                // - 2
                //   - 21
                // - 3
                TreeViewSelectionChangedEventArgs selectionChangedEventArgs = null;

                var treeView = new TreeView {
                    SelectionMode = TreeViewSelectionMode.Multiple
                };
                treeView.SelectionChanged += (s, e) => selectionChangedEventArgs = e;

                var node1 = new TreeViewNode {
                    Content = "1", IsExpanded = true
                };
                var node11 = new TreeViewNode {
                    Content = "11"
                };
                var node12 = new TreeViewNode {
                    Content = "12"
                };
                var node13 = new TreeViewNode {
                    Content = "13"
                };
                node1.Children.Add(node11);
                node1.Children.Add(node12);
                node1.Children.Add(node13);

                var node2 = new TreeViewNode {
                    Content = "2", IsExpanded = true
                };
                var node21 = new TreeViewNode {
                    Content = "21"
                };
                node2.Children.Add(node21);

                var node3 = new TreeViewNode {
                    Content = "3"
                };

                treeView.RootNodes.Add(node1);
                treeView.RootNodes.Add(node2);
                treeView.RootNodes.Add(node3);
                Content = treeView;
                Content.UpdateLayout();

                var tvi1  = (TreeViewItem)treeView.ContainerFromItem(node1);
                var tvi11 = (TreeViewItem)treeView.ContainerFromItem(node11);
                var tvi12 = (TreeViewItem)treeView.ContainerFromItem(node12);
                var tvi13 = (TreeViewItem)treeView.ContainerFromItem(node13);
                var tvi2  = (TreeViewItem)treeView.ContainerFromItem(node2);
                var tvi21 = (TreeViewItem)treeView.ContainerFromItem(node21);
                var tvi3  = (TreeViewItem)treeView.ContainerFromItem(node3);

                // - 1         selected
                //   - 11      selected
                //   - 12      selected
                //   - 13      selected
                // - 2
                //   - 21
                // - 3
                tvi1.IsSelected = true;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(4, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node1));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node11));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node12));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node13));
                Verify.AreEqual(0, selectionChangedEventArgs.RemovedItems.Count);
                selectionChangedEventArgs = null;

                // - 1         selected
                //   - 11
                //   - 12      selected
                //   - 13      selected
                // - 2
                //   - 21
                // - 3
                tvi11.IsSelected = true;
                tvi11.IsSelected = false;

                Verify.IsNotNull(selectionChangedEventArgs);
                Verify.AreEqual(0, selectionChangedEventArgs.AddedItems.Count);
                Verify.AreEqual(1, selectionChangedEventArgs.RemovedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.RemovedItems.Contains(node11));
                selectionChangedEventArgs = null;

                // - 1         selected
                //   - 11      selected
                //   - 12      selected
                //   - 13      selected
                // - 2         selected
                //   - 21      selected
                // - 3         selected
                treeView.SelectAll();
                Verify.IsNotNull(selectionChangedEventArgs);
                var items = selectionChangedEventArgs.AddedItems.ToList();
                Verify.AreEqual(7, selectionChangedEventArgs.AddedItems.Count);
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node1));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node11));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node12));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node13));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node2));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node21));
                Verify.IsTrue(selectionChangedEventArgs.AddedItems.Contains(node3));
                Verify.AreEqual(0, selectionChangedEventArgs.RemovedItems.Count);
            });
        }
 public RxTreeViewEvents(TreeView data) : base(data)
 {
     _data = data;
 }