Multiprocotol Terminalprogram (BAT)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MultiTerm/MultiTerm.Wpf/ValueConverters/ProtocolTypeToIconConverter.cs

40 lines
1.4 KiB

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 path = $"{typeof(MainWindow).FullName};component/Assets/";
//string packUri = "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();
}
}