コード例 #1
0
        public void TreeViewItemSourceResetRecreateItems()
        {
            RunOnUIThread.Execute(() =>
            {
                ExtendedObservableCollection <TreeViewItemSource> items
                    = new ExtendedObservableCollection <TreeViewItemSource>();
                TreeViewItemSource item1 = new TreeViewItemSource()
                {
                    Content = "item1"
                };
                TreeViewItemSource item2 = new TreeViewItemSource()
                {
                    Content = "item2"
                };
                TreeViewItemSource item3 = new TreeViewItemSource()
                {
                    Content = "item3"
                };
                items.Add(item1);
                items.Add(item2);
                items.Add(item3);

                var treeView         = new TreeView();
                treeView.ItemsSource = items;

                Verify.AreEqual(treeView.RootNodes.Count, 3);
                Verify.AreEqual(treeView.RootNodes[0].Content as TreeViewItemSource, items[0]);

                List <TreeViewItemSource> newItems = new List <TreeViewItemSource>();
                TreeViewItemSource item4           = new TreeViewItemSource()
                {
                    Content = "item4"
                };
                TreeViewItemSource item5 = new TreeViewItemSource()
                {
                    Content = "item5"
                };

                newItems.Add(item4);
                newItems.Add(item5);

                items.ReplaceAll(newItems);

                Verify.AreEqual(treeView.RootNodes.Count, 2);
                Verify.AreEqual(treeView.RootNodes[0].Content as TreeViewItemSource, items[0]);
            });
        }