Silverlight 4 MVVM DataGrid AND Child Window Pass Data back to Parent Window -


i need help. have silverlight application parent form has search button when clicked loads modaldialog has 3 text boxes, 2 button(for searchin , resetting) , datagrid (telerik gridview, can change grid not problem). enter search criteria on 1 of buttons, last name, , records particular lastname loaded on grid. need able select row on grid , having done so, details of selected row should updated on controls on parent window (there no grid on parent window, data entry form). using mvvm. how acheive while keeping true mvvm pattern? have seen alot of stuff on passing data parent child none on child parent/calling window.

any help, , simple code example, highly appreciated. been on whole 3days , aint figuring out yet.

francis.

i've done in mvvm light toolkit using messaging. uses called "pubsub", means "publish message, subscribe message"

i use command in gridview of modal window. here's xaml that:

<i:interaction.triggers>     <i:eventtrigger eventname="selectionchanged">         <cmd:eventtocommand command={binding itemselectedcommand} />     </i:eventtrigger> </i:interaction.triggers> 

depending on flavor (if any) of mvvm toolkit you're using, syntax might different. in case, said, mvvm light. i'm using icommand interface pass command view model. in case, cmd reference pointing galasoft.mvvmlight.command:

xmlns:cmd="clr-namespace:galasoft.mvvmlight.command;assembly=galasoft.mvvmlight.extras.sl4" 

in viewmodel child window, register command, , when it's triggered, call line:

messenger.default.send<tsmvvm.model.workorders>(selectedworkorder); 

this line publishes (sends) message of type workorders (which model class in app), passing through selectedworkorder. line of code sits inside of command, fired off on selectionchanged event of gridview. example code is:

_itemselectedcommand = new relaycommand(workorderselected);  private void workorderselected()  {     messenger.default.send<tsmvvm.model.workorders>(selectedworkorder); } 

in parent window, in constructor, have this:

messenger.default.register<tsmvvm.model.workorders>(this, setworkorder); 

this line registers (or subscribes) message of type workorders. time message sent through app, of type workorder, calls function: setworkorder, below:

private void setworkorder(tsmvvm.model.workorders wo)      {         this.selectedwo = wo;     } 

my dataform has itemssource bound workorders, , currentitem bound selectedwo, set twoway binding. when update selectedwo (implementing inotifypropertychanged, via mvvm light toolkit's viewmodelbase), dataform updates accordingly.

if need more info, let me know!

scott


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -