Skip to content

Instantly share code, notes, and snippets.

@dotMorten
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotMorten/6fe30e2106e4dad1f248 to your computer and use it in GitHub Desktop.
Save dotMorten/6fe30e2106e4dad1f248 to your computer and use it in GitHub Desktop.
Base class for IValue converter that abstracts away .NET and Windows Runtime IValueConverter differences. Inherit from this instead of IValueConverter
using System;
#if NETFX_CORE
using Windows.UI.Xaml.Data;
#else
using System.Windows.Data;
#endif
namespace SampleApp.Common
{
/// <summary>
/// Base converter class for handling converter differences between .NET and Windows Runtime
/// </summary>
public abstract class BaseValueConverter : IValueConverter
{
#if NETFX_CORE
object IValueConverter.Convert(object value, Type targetType, object parameter, string language)
#else
object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
#endif
{
#if !NETFX_CORE
string language = culture.TwoLetterISOLanguageName;
#endif
return Convert(value, targetType, parameter, language);
}
protected abstract object Convert(object value, Type targetType, object paramter, string language);
#if NETFX_CORE
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, string language)
#else
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
#endif
{
#if !NETFX_CORE
string language = culture.TwoLetterISOLanguageName;
#endif
return ConvertBack(value, targetType, parameter, language);
}
protected abstract object ConvertBack(object value, Type targetType, object paramter, string language);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment