54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
// Copyright (c) 2017 schick Informatik
|
|
// Description: Helper converter for empty image source
|
|
//
|
|
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
using System.Windows.Markup;
|
|
|
|
namespace ENI2.Util
|
|
{
|
|
public class NullImageConverter : MarkupExtension, IValueConverter
|
|
{
|
|
|
|
#region MarkupExtension implementation
|
|
|
|
private static NullImageConverter _converter = null;
|
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
{
|
|
if (_converter == null)
|
|
{
|
|
_converter = new NullImageConverter();
|
|
}
|
|
return _converter;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IValueConverter implementation
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value == null)
|
|
return DependencyProperty.UnsetValue;
|
|
return value;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
// According to https://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.convertback(v=vs.110).aspx#Anchor_1
|
|
// (kudos Scott Chamberlain), if you do not support a conversion
|
|
// back you should return a Binding.DoNothing or a
|
|
// DependencyProperty.UnsetValue
|
|
return Binding.DoNothing;
|
|
// Original code:
|
|
// throw new NotImplementedException();
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|