Last active
April 9, 2021 18:26
-
-
Save luiseduardohd/b14723631bf3659c1a2bb4c8b1b9d9f9 to your computer and use it in GitHub Desktop.
TypedValueConverter to have typed objects in the conversion
This file contains 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
public abstract class TypedValueConverter<TObject, TTarget> : IValueConverter | |
{ | |
public Type targetType { get; set; } | |
public object parameterConvert { get; set; } | |
public object parameterConvertBack { get; set; } | |
public CultureInfo cultureInfo { get; set; } | |
public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo) | |
{ | |
this.targetType = targetType; | |
this.parameterConvert = parameter; | |
this.cultureInfo = cultureInfo; | |
return Convert((TObject)value); | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo) | |
{ | |
this.targetType = targetType; | |
this.parameterConvertBack = parameter; | |
this.cultureInfo = cultureInfo; | |
return ConvertBack((TTarget)value); | |
} | |
public abstract TTarget Convert(TObject value); | |
public abstract TObject ConvertBack(TTarget target); | |
} | |
public abstract class TypedValueConverter<TObject,TTarget,TConverParameter, TConverBackParameter> : IValueConverter | |
{ | |
public Type targetType { get; set; } | |
public TConverParameter parameterConvert { get; set; } | |
public TConverBackParameter parameterConvertBack { get; set; } | |
public CultureInfo cultureInfo { get; set; } | |
public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo) | |
{ | |
this.targetType = targetType; | |
this.parameterConvert = (TConverParameter)parameter; | |
this.cultureInfo = cultureInfo; | |
return Convert((TObject)value); | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo) | |
{ | |
this.targetType = targetType; | |
this.parameterConvertBack = (TConverBackParameter)parameter; | |
this.cultureInfo = cultureInfo; | |
return ConvertBack((TTarget)value); | |
} | |
public abstract TTarget Convert(TObject value); | |
public abstract TObject ConvertBack(TTarget target); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment