29 lines
739 B
C#
29 lines
739 B
C#
// Copyright (c) 2017- schick Informatik
|
|
// Description: Validation for direct in-grid editing
|
|
//
|
|
|
|
|
|
using System.Globalization;
|
|
using System.Windows.Controls;
|
|
|
|
namespace ENI2.Util
|
|
{
|
|
public class StringValidationRule : ValidationRule
|
|
{
|
|
|
|
public int MaxLength { get; set; } = 100;
|
|
|
|
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
|
{
|
|
if ((value is string text) && text.Length > MaxLength)
|
|
{
|
|
return new ValidationResult(false, string.Format("Text is longer than {0} chars", MaxLength));
|
|
}
|
|
else
|
|
{
|
|
return new ValidationResult(true, null);
|
|
}
|
|
}
|
|
}
|
|
}
|