Пример #1
0
        public async Task When_Sublist_Of_Last_Item_Cleared()
        {
            var initial_Depth_0 = 0;
            var initial_Depth_1 = 64;
            var initial_Depth_2 = 96;

            var treeView = new Microsoft.UI.Xaml.Controls.TreeView();

            treeView.ItemTemplate = TreeViewItemTemplate;
            var testViewModelItems = Enumerable.Range(0, 2).Select(_ => Get_Depth_0_Item()).ToArray();

            treeView.ItemsSource       = testViewModelItems;
            WindowHelper.WindowContent = treeView;

            await WindowHelper.WaitForLoaded(treeView);

            await WindowHelper.WaitForNonNull(() => treeView.ContainerFromItem(testViewModelItems.Last().Items.First().Items.Last()));

            var currentItem = testViewModelItems.First().Items.Last().Items.First();

            Assert.IsNotNull(treeView.ContainerFromItem(currentItem));

            testViewModelItems.First().Items.Last().Items.Clear();

            await WindowHelper.WaitFor(() => treeView.ContainerFromItem(currentItem) == null);

            TestViewModelItem Get_Depth_0_Item() => new TestViewModelItem
            {
                Label = $"Item {++initial_Depth_0}",
                Items =
                {
                    Get_Depth_1_Item(),
                    Get_Depth_1_Item(),
                    Get_Depth_1_Item(),
                }
            };

            TestViewModelItem Get_Depth_1_Item() => new TestViewModelItem
            {
                Label = $"Subitem {(char)(++initial_Depth_1)}",
                Items =
                {
                    Get_Depth_2_Item(),
                    Get_Depth_2_Item(),
                }
            };
            TestViewModelItem Get_Depth_2_Item() => new TestViewModelItem
            {
                Label = $"Subitem {(char)(++initial_Depth_2)}"
            };
        }
Пример #2
0
 public void ValidateTreeViewItemSourceChangeUpdatesChevronOpacity()
 {
     RunOnUIThread.Execute(() =>
     {
         var treeView   = new TreeView();
         var collection = new ObservableCollection <int>();
         collection.Add(5);
         treeView.ItemsSource = collection;
         Content = treeView;
         Content.UpdateLayout();
         var tvi = (TreeViewItem)treeView.ContainerFromItem(5);
         Verify.AreEqual(tvi.GlyphOpacity, 0.0);
         tvi.ItemsSource = collection;
         Content.UpdateLayout();
         Verify.AreEqual(tvi.GlyphOpacity, 1.0);
     });
 }
Пример #3
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);
            });
        }
Пример #4
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));
            });
        }