50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
// Copyright (c) 2023- schick Informatik
|
|
// Description: Simple converter to check if a numeric value is greater than a specific value. This can
|
|
// be used by datatriggers in XAML
|
|
//
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
using System.Windows.Markup;
|
|
|
|
namespace ENI2.Util
|
|
{
|
|
public class CutoffConverter : MarkupExtension, IValueConverter
|
|
{
|
|
|
|
#region MarkupExtension implementation
|
|
|
|
private static CutoffConverter _converter = null;
|
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
{
|
|
if (_converter == null)
|
|
{
|
|
_converter = new CutoffConverter();
|
|
}
|
|
return _converter;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IValueConverter implementation
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is ICollection collection)
|
|
return collection.Count > Cutoff;
|
|
return ((int)value) > Cutoff;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
#endregion
|
|
|
|
public int Cutoff { get; set; }
|
|
}
|
|
}
|