26 lines
799 B
C#
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;
|
|
}
|
|
} |