0

I have a method in my MouthDiseaseViewModel

public void Insert(MouthDisease entity, DetailsUserControl userCon)
{
    //some code for saving to the db    
}

How can I pass these two parameters (1 MouthDisease object and a UserControl) to the command button parameter?

<Button Content="Update" Command="{Binding MouthInsertCommand}" >
        <Button.CommandParameter>
            <Binding></Binding><!--stuck here-->
        </Button.CommandParameter>                    
</Button>

EDIT

This is not a duplicate! I saw the link that Peter put and it has two parameters with the same type and the same element. I was pointing that my parameters are an object from the ViewModel and the current UserControl from the view. All of the samples i've seen were about width and height or tag and name that has the same data types.

anyway, as Tseng pointed out, I violated the pattern. I thought View and Model are the only classes that should not reference with each other.

so as I edit this, what if my ViewModel.Insert's signature is like this:

public void Insert(MouthDisease entity, User currentUser)
{
    //some code for saving to the db    
}

How do I write this method with two different data types in markup?

Pamingkas Sevada
  • 432
  • 9
  • 21
  • Have a look at this question - http://stackoverflow.com/questions/5105233/multiple-parameter-to-pass-to-command-wpf – Stuart Oct 02 '15 at 19:52
  • Instead of a command, you can create a WPF converter class hat implements IMultiValueConverter, which can receive multiple values as you want here. – Tore Aurstad Oct 02 '15 at 20:03
  • You should stop right there. What you do violates MVVM pattern and is plain wrong. ViewModel is not allowed to have ANY Reference to the View. To achieve this you have to create multiple assemblies for Views, ViewModels and rest of your domain (models, services etc) and ViewModel assembly **MUST NOT** reference to View assembly or **ANY** Presentation.dll/WPF related assemblies – Tseng Oct 02 '15 at 23:10
  • Do you really need to pass the second parameter at this point? Why can't MouseDiseaseViewModel get a reference of the current User in its constructor? – atomaras Oct 04 '15 at 17:13

0 Answers0