"pass the value of one control to a converter to set the width on another control" Code Answer

1

you're supposed to use the other control as the source, not the parameter. the parameter has to be a constant and in your case can be -5.

i'm not near vs at the moment so the syntax maybe inaccurate, however, it is something like:

width="{binding elementname=layoutroot, path=actualwidth,
converter={staticresource positionconverter}, converterparameter=-5}"

(the converter will receive -5 as a string and will have to convert it into a number before using it.)

from my experience it is better to use the onxxxchanged callback of dependecyproperty xxx, and not bind controls within the same window/root control one to another. one of the reasons for this is that you may want to bind them to an external element later on.

or alternatively, use multibinding:

<textblock>
    <textblock.width>
        <multibinding converter="{staticresource yourconverter}">
            <multibinding.bindings>
                <binding /> <!-- bind to parameter 1 here -->
                <binding /> <!-- bind to parameter 2 here -->
          </multibinding.bindings>
        </multibinding>
    </textblock.width>
</textblock>

and and a converter which converts the two parameters to the value you want.

By jss367 on May 12 2022

Answers related to “pass the value of one control to a converter to set the width on another control”

Only authorized users can answer the Search term. Please sign in first, or register a free account.