Files
Shrlalgo.RvKits/Melskin/Converters/Internal/InterlacedBackgroundConverter.cs
2026-02-17 22:17:13 +08:00

30 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Globalization;
using System.Windows.Data;
namespace Melskin.Converters.Internal;
/// <summary>
/// 隔行交错背景颜色
/// </summary>
[ValueConversion(typeof(int), typeof(Visibility))]
public class InterlacedBackgroundConverter : IValueConverter
{
/// <summary>
/// InterlacedBackgroundConverter 的单例实例,用于提供隔行交错背景颜色的转换功能。
/// 该实例可以直接在XAML中通过静态资源引用以便为列表项等控件设置交替背景颜色。
/// </summary>
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;
}
}