using MultiTerm.Protocols.Types; using System; using System.Globalization; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media.Imaging; namespace MultiTerm.Wpf.ValueConverters; [ValueConversion(typeof(ProtocolType), typeof(Image))] internal class ProtocolTypeToIconConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if(value is not ProtocolType protocolType) { throw new ArgumentException($"Wrong object provided, can only convert from type {nameof(ProtocolType)}"); } string resourceFolderPath = "pack://application:,,,/Assets/"; string fileName = protocolType switch { ProtocolType.Serial => "mdi-serial-port.png", ProtocolType.UsbHid => "mdi-keyboard.png", ProtocolType.Tcp_Client => "mdi-network.png", ProtocolType.Udp => "mdi-network.png", _ => throw new NotImplementedException(), }; var uriSource = new Uri(resourceFolderPath + fileName); return new BitmapImage(uriSource); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }