Sviluppo TradingBot
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace DesktopBot.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converte una IEnumerable in una collezione limitata ai primi N elementi.
|
||||
/// Parametro: numero massimo di elementi da visualizzare (default 50).
|
||||
/// </summary>
|
||||
public class MaxItemsConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is IEnumerable enumerable))
|
||||
return value;
|
||||
|
||||
// Estrai il parametro per il limite
|
||||
int maxItems = 50;
|
||||
if (parameter != null && int.TryParse(parameter.ToString(), out int parsedMax))
|
||||
maxItems = parsedMax;
|
||||
|
||||
// Converti a lista e prendi gli ultimi N elementi (ordine LIFO)
|
||||
var list = enumerable.Cast<object>().Take(maxItems).ToList();
|
||||
return new ObservableCollection<object>(list);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user