Sviluppo TradingBot
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace DesktopBot.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converter che restituisce lo stile NavItemActive se il tab corrisponde,
|
||||
/// altrimenti NavItem (usato nella barra di navigazione laterale)
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converter per i colori dei log in base al livello
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Inverte un valore booleano (usato per il radio button Live/Paper)</summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>bool → Visibility (true=Visible, false=Collapsed)</summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>bool → Visibility invertito (true=Collapsed, false=Visible)</summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>null → Visible, not-null → Collapsed (placeholder "nessun bot selezionato")</summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>not-null → Visible, null → Collapsed (mostra pannello dettaglio)</summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>stringa vuota/null → Visible (placeholder search), non-vuota → Collapsed</summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>int 0 → Collapsed, >0 → Visible (usato per nascondere la lista risultati vuota)</summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>bool IsProfit → verde o rosso per P&L</summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converter per il colore dell'indicatore di streaming.
|
||||
/// True (streaming attivo) → Verde, False (fermo) → Grigio
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user