How to pass a variable as Converterparameter in WPF

You can use MultiBinding for this purpose.
First, implement LengthConverter as IMultiValueConverter:

public sealed class LengthConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        // values array will contain both MinimumRebarsVerticalDistance and 
        // CurrentDisplayUnit values
        // ...
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        // ...
    }
}

Second, bind TextBox.Text with multibinding:

        <TextBox.Text>
            <MultiBinding Converter="{StaticResource LengthConverter}">
                <Binding Path="MinimumRebarsVerticalDistance"/>
                <Binding Path="CurrentDisplayUnit" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}"/>
            </MultiBinding>
        </TextBox.Text>

Note 1: RelativeSource.AncestorType depends on where CurrentDisplayUnit property is declared (the sample is for window's code behind).

Note 2: looks like CurrentDisplayUnit should be a view model property.

Tags:

C#

Wpf