Last active
August 29, 2015 14:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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