design patterns - How can I build UI on the fly in my view model -


i have wholly adopted mvvm pattern our silverlight app. however, of our ui data driven. 2 items...

  1. the menu. using infragistics xammenu.

  2. we have "dashboard" allows users add "snap-ins". sort of portal site such igoogle.

in both cases above ui needs built @ runtime. running code in code behind because don't see easy way access ui tree in viewmodel.

in order run code in view have created event in viewmodel fires once data loaded. so, have kludge reference viewmodel in view code behind. don't ugly... 2 question:

  1. how can have view message viewmodel data loaded without getting direct reference viewmodel in view code behind? pull reference data context.

  2. is possible build ui in view model , use data binding. wondering if bind "content" of contentcontrol type (not sure type be) in viewmodel? of course, bad part testability of view model seems go away. can binding used way?

to answer question 1, why dont make use of mvvm light "messenger" class.

in view,you register listen message in following way:

messenger.default.register<bool>(this, "messageid", dosomething); 

where dosomething method takes in boolean parameter (for example).

then, send message view model, following:

 messenger.default.send(false, "messageid"); 

hope helps :) you'll need add usings:

using galasoft.mvvmlight.messaging; 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -