public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // Get the full path var path = (string)value; // If the path is null, ignore if (path == null) { return(null); } // Get the name of the item: file/folder var name = DirectoryStructure.GetFileFolderName(path); // Let's assume it is a file just in case var image = "Images/file.png"; // If the name is blank, we presume it's a drive as we cannot have blank file or folder name if (string.IsNullOrEmpty(name)) { image = "Images/drive.png"; } else if (new FileInfo(path).Attributes.HasFlag(FileAttributes.Directory)) { image = "Images/folder-closed.png"; } return(new BitmapImage(new Uri($"pack://application:,,,/{image}"))); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string path = (string)value; if (path == null) { return(null); } //by default we presume an image string image = "Images/file.png"; string name = DirectoryStructure.GetFileFolderName(path); if (string.IsNullOrEmpty(name)) { image = "Images/drive.png"; } else if ((new FileInfo(path)).Attributes.HasFlag(FileAttributes.Directory)) { image = "Images/folder-closed.png"; } else { } return(new BitmapImage(new Uri($"pack://application:,,,/{image}"))); }
public DirectoryStructureViewModel() { var children = DirectoryStructure.GetLogicalDrives(); this.Items = new ObservableCollection <DirectoryItemViewModel>( children.Select(drive => new DirectoryItemViewModel(drive.FullPath, DirectoryItemType.Drive))); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { //get the full path var path = (string)value; //if the path is null, ignore if (path == null) { return(null); } //get the name of the file/folder var name = DirectoryStructure.GetFileFolderName(path); //by default we presume an image var image = "Images/C.jpg"; //if the name is blank, we presume it's a drive (we cannot have a blank file/image name) if (string.IsNullOrEmpty(name)) { image = "Images/A.jpg"; } else if (new FileInfo(path).Attributes.HasFlag(FileAttributes.Directory)) { image = "Images/B.jpg"; } return(new BitmapImage(new Uri($"pack://application:,,,/{image}"))); }
/// <summary> /// Convert a full path to a specific image type of a drive folder or file /// </summary> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var name = DirectoryStructure.GetFileFolderName(path); //by default, we presume an image var image = "Images/download.jpg"; switch ((DirectoryItemType)value) { case DirectoryItemType.Drive: image = "Image/drive.png"; break; case DirectoryItemType.Folder: image = "Image/download.jpg"; break; } // if the name is blank we presume it's a drive as we cannot have a blank file or folder name if (string.IsNullOrEmpty(name)) { image = "Images/download.jpg"; } else if (new FileInfo(path).Attributes.HasFlag(FileAttributes.Directory)) { image = "Images/afv_icon.png"; } return(new BitmapImage(new Uri($"pack://application:,,,/{image}"))); }
/// <summary> /// Default constructor /// </summary> public DirectoryStructureViewModel() { //Get all logical drives var children = DirectoryStructure.GetLogicalDrives(); //Get view models from the data this.Items = new ObservableCollection <DirectoryItemViewModel>(children.Select(drive => new DirectoryItemViewModel(drive.FullPath, DirectoryItemType.Drive))); }
private void Expand() { if (this.Type == DirectoryItemType.File) { return; } this.Children = new ObservableCollection <DirectoryItemViewModel>(DirectoryStructure.GetDirectoryContents(this.FullPath).Select(content => new DirectoryItemViewModel(content.FullPath, content.Type))); }
/// <summary> /// Default constructor /// </summary> public DirectoryStructureViewModel() { // Get the logical drives var children = DirectoryStructure.GetLogicalDrives(); // Create the view models from the data this.Items = new ObservableCollection <DirectoryItemViewModel>( children .Select(drive => new DirectoryItemViewModel(drive.FullPath, DirectoryItemType.Drive)).OrderBy(drive => drive.FullPath, new NaturalStringComparer())); this.SelectedItems = new ObservableCollection <DirectoryItemViewModel>(); }
/// <summary> /// Expands this item /// </summary> private void Expand() { // We cannot expand a file if (this.Type == DirectoryItemType.File) { return; } // Find all children var children = DirectoryStructure.GetDirectoryContent(this.FullPath).Select(content => new DirectoryItemViewModel(content.FullPath, content.Type)); this.Children = new ObservableCollection <DirectoryItemViewModel>(children); }
/// <summary> /// Expand this directory item. /// </summary> private void Expand() { // we cannt expand file. if (Type == DirectoryItemType.File) { return; } // Find all children var children = DirectoryStructure.GetDirectoryContents(this.FullPath); this.Children = new ObservableCollection <DirectoryItemViewModel>( children.Select(item => new DirectoryItemViewModel(item.FullPath, item.Type))); }
/// <summary> /// Expands this directory and finds all children /// </summary> private void Expand() { // We cannot expand a file if (this.Type == DirectoryItemType.File) { return; } // Find all children var children = DirectoryStructure.GetDirectoryContents(this.FullPath); this.Children = new ObservableCollection <DirectoryItemViewModel>( children .Select(content => new DirectoryItemViewModel(content.FullPath, content.Type)).OrderBy(folder => folder.FullPath, new NaturalStringComparer())); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var path = (string)value; //if the path is null, ignore if (path == null) return null; var name = DirectoryStructure.GetFileFolderName(path); var image = "Images/file.png"; if (string.IsNullOrEmpty(name)) image = "Images/drive.png"; else if (new FileInfo(path).Attributes.HasFlag(FileAttributes.Directory)) image = "Images/folder-closed.png"; return new BitmapImage(new Uri($"pack://application:,,,/{image}")); }
public DirectoryStructureViewModel() { var logicalDrives = DirectoryStructure.GetLogicalDrives(); this.Items = new ObservableCollection <DirectoryItemViewModel>(logicalDrives.Select(drive => new DirectoryItemViewModel(drive.FullPath, drive.Type))); }
/// <summary> /// default constructor /// </summary> public DirectoryStructureViewModel() { var children = DirectoryStructure.GetLocalDrives(); }