Click here to Skip to main content
15,915,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a custom command, which switches between two grids. Now i want to make a sort of command template, an as parameters i want to use the two grids?
is there any way for realizing this?

thanks Moti
Posted

1 solution

Firstly, if you are 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:
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.

C#
<button content="Zoom" command="{Binding MyViewModel.ZoomCommand" commandparameter="{Binding" elementname="MyCanvas," path="Width}"<br" mode="hold" />    <button.commandparameter>
        <multibinding converter="{StaticResource YourConverter}">
             <binding path="Width" elementname="MyCanvas" />
             <binding path="Height" elementname="MyCanvas" />
        </multibinding>
    </button.commandparameter>


In your converter:
C#
public class YourConverter : IMultiValueConverter
{
    public object Convert(object[] values, ...)
    {
        return values;
    }
    ...
}


Then, in your command execution logic:
C#
public void OnExecute(object parameter)
{
    var values = (object[])parameter;
    var width = (double)values[0];
    var height = (double)values[1];
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900