Files
CRSim/CRSim.ScreenSimulator/Converters/NumberToStringConverter.cs
2025-04-05 22:12:38 +08:00

39 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace CRSim.ScreenSimulator.Converters
{
public class NumberToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value is int l)
{
if (l < 9)
{
return $"1-{l}";
}
if (l % 2 == 0)
{
return (new List<string> { $"1-{l / 2}", $"{l / 2 + 1}-{l}" })[l.GetHashCode() % 2];
}
else
{
return (new List<string> { $"1-{(l + 1) / 2}", $"{(l + 1) / 2}-{l}" })[l.GetHashCode() % 2];
}
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}