Use method calls when expressions reach their limits or you want to reuse expressions in different places.
Either declare a client-side method in your assembly or use script methods. In both cases the signature of the method must have as many transfer parameters as the number of properties bound in the multibinding.
In our example, the script method would look like this:
- Press the "New Client Method" button (1).
- Give the method a name in the "Method info" tab (2).
- Program the script method (3). In our example we named it "ConvertExampleA".
Now switch to the design where you want to use the method and open the trigger window to create a data trigger. Proceed as described in the previous section and repeat steps 1-4. Instead of step 5, in which lambda expressions were declared, we now need the method call. To do this, open the "Methods" expander and "Drag & Drop" the "ConvertExampleA" method onto the converter:
In the converter editor window, the mode was set to "ScriptEngine" and the address for calling the method is in the url. Close the trigger window and switch to the XAML editor. The following code was generated:
Essentially, the XAML code is similar to the code from the section "Setting and converting properties" because, on the one hand, multibinding was used in combination with converters. The difference, however, is that the method does not return an instance from the System.Windows or System-Drawing namespace. This creates a separation between model and presentation in accordance with the MVVM pattern, because the presentation takes place declaratively using setter objects.