using C4IT.FASD.Base; using F4SD_AdaptableIcon; using F4SD_AdaptableIcon.Enums; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; namespace FasdDesktopUi.Basics.Converter { /// /// Manages conversion between and /// internal class IconDataConverter : IValueConverter { /// /// Converts to /// /// The icon data of type internal static IconData Convert(cFasdIcon iconConfig) { switch (iconConfig.IconType) { case enumIconType.intern: if (Enum.TryParse(iconConfig.Name, out enumInternIcons intern)) return new IconData(intern); break; case enumIconType.material: if (Enum.TryParse(iconConfig.Name, out MaterialIcons.MaterialIconType material)) return new IconData(material); break; case enumIconType.gif: if (Enum.TryParse(iconConfig.Name, out enumInternGif gif)) return new IconData(gif); break; } return new IconData(enumInternIcons.none); } /// /// Converts to /// /// The icon data of type public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (targetType != typeof(IconData)) return null; if (!(value is cFasdIcon iconConfig)) return new IconData(enumInternIcons.none); return Convert(iconConfig); } /// /// Converts to /// /// The configuration of type public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is IconData iconData)) return null; if (iconData.Intern != null) return new cFasdIcon() { IconType = enumIconType.intern, Name = iconData.Intern.ToString(), IsValid = true }; else if (iconData.Material != null) return new cFasdIcon(iconData.Material.Value); else if (iconData.Gif != null) return new cFasdIcon() { IconType = enumIconType.gif, Name = iconData.Gif.ToString(), IsValid = true }; return null; } } }