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
Post a Comment