Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
550
Re: Boolean Converter
posted

Hi,

i need to apply convertor dynamically depending on the the conditions applied by user.

how do i do this.

 i have a covetrtor class where i need to pass the configration set by user a parameter and bind this to a specific column mentoned in config.

how do i do it dynamically?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

public class ValueToStringConverter :

IValueConverter

{

 

 

 

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo

culture)

{

 

 

 

 

ReplacementRuleConfig obj = parameter as ReplacementRuleConfig

;


 

 

 

string[] strarr = obj.RuleExpression.Split(new char[] { '='

});


 

 

 

string

strColName = strarr[0];


 

 

 

string

strColVal = strarr[1];


 

 

 

string str = value as string

;


 

 

 

if (String

.IsNullOrEmpty(str))

{

 

 

 

 

return string

.Empty;

}

 

 

 

 

try

{

 

 

 

if

(str == strColVal)

{

 

 

 

 

return

obj.RuleReplacementString;

}

}

 

 

 

 

catch

{

}

 

 

 

return

str;

 

}

 

 

 

 

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo

culture)

{

 

 

 

 

return string

.Empty;

 

 

  • 21382
    posted

    Off the Column object where you would set the ValueConverter is a property called .ValueConverterParameter, so if you could use that to pass in the information