I have a command which I am executing from my XAML file using the following standard syntax:
<Button Content="Zoom" Command="{Binding MyViewModel.ZoomCommand}"/>
This worked fine until I realized that I needed TWO pieces of information from the view in order to make this operation complete the way users expect (the width and height of the canvas specfically).
It seems like it's possible to pass an array as an argument to my command, but I don't see there being a way to specify the binding to my two canvas properties in the CommandParameter:
<Button Content="Zoom"
Command="{Binding MyViewModel.ZoomCommand"
CommandParameter={Binding ElementName=MyCanvas, Path=Width}"/>
How do I pass both Width and Height to my command? It doesn't seem like this is possible using commands from XAML and I need to wire up a click handler in my codebehind to get this information to pass to my zoom method.
About using Tuple in Converter, it would be better to use 'object' instead of 'string', so that it works for all types of objects without limitation of 'string' object.
Then execution logic in Command could be like this
and multi-bind with converter to create the parameters (with two TextBox objects)
In the converter of the chosen solution, you should add values.Clone() otherwise the parameters in the command end null
Use Tuple in Converter, and in OnExecute, cast the parameter object back to Tuple.
Firstly, if you're doing MVVM you would typically have this information available to your VM via separate properties bound from the view. That saves you having to pass any parameters at all to your commands.
However, you could also multi-bind and use a converter to create the parameters:
In your converter:
Then, in your command execution logic: