Exemple #1
0
        private static ObservableCollection <object> CreateItems(Random random, DemoItem parent, int depth, int maxDepth, int labelIndex = 0)
        {
            int itemsCount = random.Next((int)Math.Pow(10, depth + 1));
            var items      = new ObservableCollection <object>();

            for (int itemIndex = 0; itemIndex < itemsCount; itemIndex++)
            {
                if (random.Next(11) == 0)
                {
                    var errorItem = new ErrorItem();
                    items.Add(errorItem);
                }
                else
                {
                    var item = new DemoItem();
                    item.Label      = (parent != null ? parent.Label + "." : "") + ++labelIndex;
                    item.IsExpanded = random.Next(5) == 0;
                    items.Add(item);
                    if (depth < maxDepth)
                    {
                        foreach (var childItem in CreateItems(random, item, depth + 1, maxDepth))
                        {
                            item._children.Add(childItem);
                        }
                    }
                }
            }
            return(items);
        }
Exemple #2
0
 private static void AppendDemoItems(ObservableCollection <object> root)
 {
     foreach (var i in DemoItem.CreateItems(2, null, root.Count))
     {
         root.Add(i);
     }
 }
Exemple #3
0
        private static void AppendFirstContent(ObservableCollection <object> root)
        {
            var firstItem = root[0] as DemoItem;

            if (firstItem == null)
            {
                root[0] = firstItem = new DemoItem {
                    Label = "1"
                }
            }
            ;
            foreach (var childItem in DemoItem.CreateItems(1, firstItem, seed: 3, labelIndex: firstItem.Children.Count))
            {
                firstItem.Children.Add(childItem);
            }
        }
Exemple #4
0
 public static ObservableCollection <object> CreateItems(int depth, DemoItem parent, int seed = 0, int labelIndex = 0) => CreateItems(new Random(seed), parent, 0, depth, labelIndex);
Exemple #5
0
 private void ResetContent(object sender, RoutedEventArgs e)
 {
     ++_contentGeneration;
     DemoItem.Root  = DemoItem.CreateItems(2, null, _contentGeneration);
     DemoItem.Root2 = DemoItem.CreateItems(2, null, _contentGeneration);
 }