0

We are normally bind the IValueConverter value like as below,

<Button x:Name="myButton" Content="ClickMe" />
<Image Opacity="{Binding ElementName=myButton, Path=IsEnabled, Converter={StaticResource BoolToOpacityConverter}, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ConverterParameter = 1}" />

But my requirement is, without using xaml bind the IValueConverter. Please anyone suggest me how to bind the IValueConverter using c# without using xaml

Yogeshwaran
  • 170
  • 12

1 Answers1

0

You would use it in c# exactly the same as if you were using any other class.

So if your value converter is like this:

public class CustomConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        // ... your custom value converter                    
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
         // ... your custom value converter                              
    }
}

you would use it like this:

var customConverter = new CustomConverter();
customConverter.Convert( .. );
Mightee
  • 689
  • 7
  • 22