Example #1
0
        // <summary>
        // A converter that organizes several collections into (optional)
        // child collections that are put into <see cref="FolderItem"/>
        // </summary>
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            //get folder name listing...
            var folder = parameter as string ?? String.Empty;
            var folders = folder.Split(',').Select(f => f.Trim()).ToList();
            //...and make sure there are no missing entries
            while (values.Length > folders.Count) folders.Add(String.Empty);

            //this is the collection that gets all top level items
            var items = new List<object>();

            for (int i = 0; i < values.Length; i++)
            {
                //make sure were working with collections from here...
                var childs = values[i] as IEnumerable ?? new List<object> { values[i] };

                string folderName = folders[i];
                if (folderName != String.Empty)
                {
                    //create folder item and assign childs
                    var folderItem = new ContainerNode { Name = folderName, Items = childs };
                    items.Add(folderItem);
                }
                else
                {
                    //if no folder name was specified, move the item directly to the root item
                    items.AddRange(childs.Cast<object>());
                }
            }

            return items;
        }
Example #2
0
        float zoom; // а эта нужна для зума колёсиком мышки

        #endregion Fields

        #region Constructors

        public MainWindow()
        {
            InitializeComponent();
            var x = new ObservableCollection<Object>();

            var y = new ContainerNode {Items = testProject.Operations, Name = "Operations"};

            x.Add(testProject.Settings);
            x.Add(y);
            OperationsTree.ItemsSource = x;
        }