Files
ShrlAlgoToolkit/NeuWPF/NeoUI/Converters/Internal/InterlacedBackgroundConverter.cs
2025-08-20 12:10:13 +08:00

26 lines
799 B
C#

using System.Globalization;
using System.Windows.Data;
namespace NeoUI.Converters;
/// <summary>
/// 隔行交错背景颜色
/// </summary>
[ValueConversion(typeof(int), typeof(Visibility))]
public class InterlacedBackgroundConverter : IValueConverter
{
public static readonly InterlacedBackgroundConverter Instance = new();
/// <inheritdoc />
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var line = (int)(value ?? throw new ArgumentNullException(nameof(value)));
return line % 2 == 0 ? Visibility.Collapsed : Visibility.Visible;
}
/// <inheritdoc />
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}