Expand folder icon example

This commit is contained in:
Unknown
2018-01-26 22:16:45 +00:00
parent e6736afa2c
commit 036f2cb722
3 changed files with 4 additions and 15 deletions

View File

@ -16,6 +16,8 @@ namespace WpfTreeView
/// </summary> /// </summary>
public DirectoryItemType Type { get; set; } public DirectoryItemType Type { get; set; }
public string ImageName => Type == DirectoryItemType.Drive ? "drive" : (Type == DirectoryItemType.File ? "file" : (IsExpanded ? "folder-open" : "folder-closed"));
/// <summary> /// <summary>
/// The full path to the item /// The full path to the item
/// </summary> /// </summary>

View File

@ -16,20 +16,7 @@ namespace WpfTreeView
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
// By default, we presume an image return new BitmapImage(new Uri($"pack://application:,,,/Images/{value}.png"));
var image = "Images/file.png";
switch ((DirectoryItemType)value)
{
case DirectoryItemType.Drive:
image = "Images/drive.png";
break;
case DirectoryItemType.Folder:
image = "Images/folder-closed.png";
break;
}
return new BitmapImage(new Uri($"pack://application:,,,/{image}"));
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

View File

@ -20,7 +20,7 @@
<HierarchicalDataTemplate ItemsSource="{Binding Children}"> <HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Image Width="20" Margin="3" <Image Width="20" Margin="3"
Source="{Binding Type, Source="{Binding ImageName,
Converter={x:Static local:HeaderToImageConverter.Instance}}" /> Converter={x:Static local:HeaderToImageConverter.Instance}}" />
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" /> <TextBlock VerticalAlignment="Center" Text="{Binding Name}" />
</StackPanel> </StackPanel>