Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing more than 1 argument to a converter

Question: How can you pass an instance of an object from the view model to a converter along with the value to be converted to a converter?


Info: I'm working on an inventory program for people on our factory floor who receive incoming shipments. While receiving a shipment they will mark down who the shipping company was and who the driver was. To do this I want to have set up a pair of combo boxes. When they select the shipper combo box and select the shipper the driver combo box will reflects this change.

My plan is to have a list of shippers (who have a list of drivers) in my ShipmentViewModel that the shipper combo box binds to. This list of shippers is only a list of GUID that i pull up from the database. the shipment's shipper will have a separate property for the shipper that is selected as well as the driver selected.

What I would like to do is pass the instance of the shipper list to the converter along with the GUID of the shipper(Gotten from the ShipmentVM). The converter compares the GUID to the list of shippers and returns to the combo box a instantiation of the ShipperVM. the driver combo box is the bound to the ShipperVM's list of drivers. Pass this list along with the driver's GUID(Also gotten from the ShipmentVM) to another converter which returns the driver's name.

I'm programing in Visual Basic and XAML according to the M-V-VM schema.

P.S. Saying "You can't pass more than 1 argument to a converter." is a totally legitimate response. I just need confirmation. I'm starting to think that this is the case...

like image 477
Narcolapser Avatar asked Feb 05 '10 19:02

Narcolapser


1 Answers

If you need to pass multiple "things" to a converter, what you actually want is a MultiValueConverter, which can accept N number of input values.

http://msdn.microsoft.com/en-us/library/system.windows.data.imultivalueconverter.aspx

like image 144
JerKimball Avatar answered Nov 03 '22 07:11

JerKimball