42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
// Copyright (c) 2017-present schick Informatik
|
|
// Description: Converter to create trimmed entries for plaintext input text fields
|
|
//
|
|
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
using System.Windows.Markup;
|
|
|
|
using bsmd.database;
|
|
|
|
namespace ENI2.Util
|
|
{
|
|
[ValueConversion(typeof(string), typeof(string))]
|
|
public class TrimStringConverter : MarkupExtension, IValueConverter
|
|
{
|
|
private TrimStringConverter _converter;
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (!((string)value).IsNullOrEmpty())
|
|
{
|
|
return ((string)value).Trim();
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return value;
|
|
}
|
|
|
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
{
|
|
if (_converter == null)
|
|
{
|
|
_converter = new TrimStringConverter();
|
|
}
|
|
return _converter;
|
|
}
|
|
}
|
|
}
|