C# and WPF tutorial files

This commit is contained in:
Unknown
2017-05-29 21:01:07 +01:00
parent dfdd754362
commit 1cb838df3a
107 changed files with 5760 additions and 0 deletions

View File

@ -0,0 +1,46 @@
using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace WpfTreeView
{
/// <summary>
/// Converts a full path to a specific image type of a drive, folder or file
/// </summary>
[ValueConversion(typeof(string), typeof(BitmapImage))]
public class HeaderToImageConverter : IValueConverter
{
public static HeaderToImageConverter Instance = new HeaderToImageConverter();
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 = "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 = "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 ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}