views:

255

answers:

2

I have legacy windows forms user control that exposses several public methods. I wrapped this control on a wpf user control and encapsulated the Methods with a relaycommand on the new wpf usercontrol.

Now my problem is how to use the mvvm pattern to execute the commands on my user control form the viewmodel that is used with the view hosting the new wpf usercontrol.

A: 

In viewmodel you have to add a field say

Public ICommand CommandOne

Now this command will create a new RelayCommand object depending upon your requirements/conditions.

Now, you can bind this 'CommandOne' command with any object say button on your control form.

So, whenever the button is clicked then the RelayCommand object will be created and it will execute the action given to it as a parameter.

Hope it works for you.

Archie
What I need to do is link the user controlcommand to the View model command so it can be called progamically inside the viewmodel
SteveP
A: 

I Fond out how to get this to work with bindings. Need to set the mode to OneWayToSource to get the command from the user control. The tricky part is that the initialization of the command has to be done inside the loaded event of the usercontrol. If you try to do it inside of the constructor, you will end up with the default initialization from the binding which could be null.

SteveP