Example #1
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string folder  = parameter as string ?? "";
            var    folders = folder.Split(',').Select(f => f.Trim()).ToList();
            int    cnt     = values.Count() / 2;

            while (values.Length * 2 > folders.Count)
            {
                folders.Add(String.Empty);
            }
            List <object> items = new List <object>();

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

                string folderName        = folders[i * 2];
                string checkPropertyName = folders[i * 2 + 1];
                if (folderName != String.Empty)
                {
                    if (!string.IsNullOrEmpty(checkPropertyName))
                    {
                        checkPropertyName = checkPropertyName.Trim();
                    }
                    TreeViewFolderItemBase folderItem = null;
                    if (string.IsNullOrEmpty(checkPropertyName))
                    {
                        folderItem = new TreeViewFolderItem {
                            FolderName = folderName, FolderItems = childs
                        };
                    }
                    else
                    {
                        folderItem = new TreeViewFolderItemWithCheck {
                            FolderName = folderName, CheckPropertyName = checkPropertyName, FolderItems = childs
                        };
                    }

                    items.Add(folderItem);
                }
                else
                {
                    //if no folder name was specified, move the item directly to the root item
                    foreach (var child in childs)
                    {
                        items.Add(child);
                    }
                }
            }
            return(items);
        }
        private void browseButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using CommonOpenFileDialog dlg = new CommonOpenFileDialog("Select a folder");
                dlg.IsFolderPicker             = true;
                dlg.InitialDirectory           = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                dlg.Multiselect             = false;
                dlg.AllowNonFileSystemItems = false;
                if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    TreeListViewItems.Clear();
                    TreeViewItems.Clear();

                    var folderPath = dlg.FileName;

                    var treeListViewFolderItem = new TreeListViewFolderItem()
                    {
                        Name     = System.IO.Path.GetFileName(folderPath),
                        FullName = folderPath,
                        IsFolder = true,
                        Source   = TreeListViewItems,
                    };
                    TreeListViewItems.Add(treeListViewFolderItem);

                    treeListViewFolderItem.IsExpanded = true;

                    TreeViewFolderItem treeViewFolderItem = new TreeViewFolderItem()
                    {
                        Name     = System.IO.Path.GetFileName(folderPath),
                        FullName = folderPath,
                        IsFolder = true,
                    };
                    TreeViewItems.Add(treeViewFolderItem);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #3
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string folder  = parameter as string ?? "";
            var    folders = folder.Split(',').Select(f => f.Trim()).ToList();

            while (values.Length > folders.Count)
            {
                folders.Add(String.Empty);
            }
            List <object> items = new List <object>();

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

                string folderName = folders[i];
                if (folderName != String.Empty)
                {
                    //create folder item and assign childs
                    TreeViewFolderItem folderItem = new TreeViewFolderItem {
                        FolderName = folderName, FolderItems = childs
                    };
                    items.Add(folderItem);
                }
                else
                {
                    //if no folder name was specified, move the item directly to the root item
                    foreach (var child in childs)
                    {
                        items.Add(child);
                    }
                }
            }
            return(items);
        }