//event handler for the Item Expanded event
        void ItemExpanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem itemExpanded = (TreeViewItem)e.OriginalSource;
            //get the object being expanded
            DirectoryDisplayItem displayItem = (DirectoryDisplayItem)itemExpanded.Header;

            //check if the children of this item are dummy items
            if (displayItem.ContainsDummyItems)
            {
                //if the children are dummy children replace them with the actual data
                displayItem.ChildItems.Clear();
                var modelData = FileSystemDataService.GetChildDirectories(displayItem.Path);
                if (modelData != null)
                {
                    var children = from x in modelData
                                   select new DirectoryDisplayItem {
                        Name = x.Name, Path = x.FullName
                    };

                    //add all the data to the list
                    foreach (var child in children)
                    {
                        displayItem.ChildItems.Add(child);
                    }
                    displayItem.ContainsDummyItems = false;
                }
            }
        }
 //load all the files for the directory
 private void LoadFiles(DirectoryDisplayItem dir)
 {
     if (dir != null)
     {
         DataSource = FileSystemDataService.GetChildFiles(dir.Path);
     }
 }
示例#3
0
 /// <summary>
 /// Checks if the specified item is a dummy item
 /// </summary>
 /// <param name="item">The item to check</param>
 /// <returns>Returns true if the item is a dummy item</returns>
 public static bool IsDummyItem(DirectoryDisplayItem item)
 {
     return(item.Name == DummyItem);
 }