c# - Passing a Parameter to ViewModel constructor -



c# - Passing a Parameter to ViewModel constructor -

is possible pass parameter viewmodel constructor? utilize parameter initialise property and/or other operations in viewmodel.

with winforms do

public myform(myparamtype myparam) { myformproperty = myparam; //etc. }

how go doing similar in mvvm pattern / using mvvm light?

any suggestions welcome. in advance.

i recommend using ioc container , configuring container supply parameter upon construction.

for instance, here's typical code-behind usercontrol looks me in wpf:

public partial class mydatagridview : imylistview { public mydatagridview() { initializecomponent(); } public mydatagridview(mylistviewmodel viewmodel) { initializecomponent(); datacontext = viewmodel; } }

structuremap creates mylistviewmodel me because default searches greediest constructor , provides dependencies. in structuremap configuration, can specify mylistviewmodel provided whatever parameters necessary upon construction of object.

with container structuremap, don't have "new" objects. ever.

c# wpf mvvm mvvm-light

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -