using System; using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Media; namespace DesktopBot.Converters { /// /// Converter che restituisce lo stile NavItemActive se il tab corrisponde, /// altrimenti NavItem (usato nella barra di navigazione laterale) /// public class NavStyleConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // Non restituiamo lo stile direttamente (non è possibile in WPF in questo modo) // Restituiamo true se il tab selezionato corrisponde al parametro return value?.ToString() == parameter?.ToString(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } /// /// Converter per i colori dei log in base al livello /// public class LogLevelColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is Models.LogLevel level) { if (level == Models.LogLevel.Success) return "#FF00E676"; if (level == Models.LogLevel.Error) return "#FFFF1744"; if (level == Models.LogLevel.Warning) return "#FFFFC107"; } return "#FF8888A0"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } /// Inverte un valore booleano (usato per il radio button Live/Paper) public class InverseBoolConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is bool b) return !b; return value; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value is bool b) return !b; return value; } } /// bool → Visibility (true=Visible, false=Collapsed) public class BoolVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value is bool b && b ? Visibility.Visible : Visibility.Collapsed; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } /// bool → Visibility invertito (true=Collapsed, false=Visible) public class InvertedBoolVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value is bool b && b ? Visibility.Collapsed : Visibility.Visible; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } /// null → Visible, not-null → Collapsed (placeholder "nessun bot selezionato") public class NullToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value == null ? Visibility.Visible : Visibility.Collapsed; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } /// not-null → Visible, null → Collapsed (mostra pannello dettaglio) public class NotNullToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value != null ? Visibility.Visible : Visibility.Collapsed; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } /// stringa vuota/null → Visible (placeholder search), non-vuota → Collapsed public class EmptyStringToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => string.IsNullOrEmpty(value as string) ? Visibility.Visible : Visibility.Collapsed; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } /// int 0 → Collapsed, >0 → Visible (usato per nascondere la lista risultati vuota) public class ZeroToCollapsedConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is int i) return i > 0 ? Visibility.Visible : Visibility.Collapsed; return Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } /// bool IsProfit → verde o rosso per P&L public class ProfitColorConverter : IValueConverter { private static readonly SolidColorBrush Green = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00E676")); private static readonly SolidColorBrush Red = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF1744")); public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value is bool b && b ? Green : (object)Red; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// TradingStrategy → Visibility. /// ConverterParameter = nome strategia (es. "EMA_CROSSOVER"). /// Visible se la strategia attiva corrisponde al parametro, Collapsed altrimenti. /// Usato nei pannelli parametri dinamici per-strategia di BotsManagerView. /// public class StrategyToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null || parameter == null) return Visibility.Collapsed; return value.ToString() == parameter.ToString() ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// Converter per il colore dell'indicatore di streaming. /// True (streaming attivo) → Verde, False (fermo) → Grigio /// public class BoolToStreamColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is bool isStreaming && isStreaming) return Colors.LimeGreen; // #00E676 return Colors.Gray; // #808080 } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } }