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 = MainWindow.GetFileFolderName(path); // By default, we assume an image var image = "images/folder.png"; // If the name is blank, wepresume it's a drive as we cannot have a blank file/folder name if (string.IsNullOrEmpty(name)) { image = "images/drive.png"; } else if (new FileInfo(path).Attributes.HasFlag(FileAttributes.Directory)) { image = "images/folder 1.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); } string name = (string)MainWindow.GetFileFolderName(path); string 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 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 = MainWindow.GetFileFolderName(path); // By default, we presume an image var image = "Z:/02-TreeViewsAndValueConverters/WpfTreeView/Images/file.png"; // 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 = "Z:/02-TreeViewsAndValueConverters/WpfTreeView/Images/drive.png"; } else if (new FileInfo(path).Attributes.HasFlag(FileAttributes.Directory)) { image = "Z:/02-TreeViewsAndValueConverters/WpfTreeView/Images/folder-open.png"; } return(new BitmapImage(new Uri(image))); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var path = (string)value; if (path == null) { return(null); } var name = MainWindow.GetFileFolderName(path); var image = "file.png"; // drives will set name = "" if (string.IsNullOrEmpty(name)) { image = "drive.png"; } else if (new FileInfo(path).Attributes.HasFlag(FileAttributes.Directory)) { image = "folder.png"; } return(new BitmapImage(new Uri(string.Format("pack://application:,,,/images/{0}", image)))); }