Files
Semi.Avalonia/demo/Semi.Avalonia.Demo/Converters/FileIconConverter.cs

28 lines
777 B
C#
Raw Normal View History

2023-07-26 16:42:17 +08:00
using System;
using System.Collections.Generic;
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Metadata;
2025-04-15 20:05:54 +08:00
namespace Semi.Avalonia.Demo.Converters;
2023-07-26 16:42:17 +08:00
2025-03-16 17:04:56 +08:00
public class FileIconConverter : IMultiValueConverter
2023-07-26 16:42:17 +08:00
{
2025-03-16 17:04:56 +08:00
[Content] public IDictionary<string, object?> Items { get; } = new Dictionary<string, object?>();
2023-07-26 16:42:17 +08:00
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
if (values[0] is bool isDirectory && values[1] is bool isOpen)
{
if (!isDirectory)
{
return Items["file"];
}
2025-03-16 17:04:56 +08:00
2023-07-26 16:42:17 +08:00
return isOpen ? Items["folderOpen"] : Items["folderClosed"];
}
2025-03-16 17:04:56 +08:00
2023-07-26 16:42:17 +08:00
return AvaloniaProperty.UnsetValue;
}
}