Friday, 15 July 2011

c# - How to pass data from viewmodel to view -



c# - How to pass data from viewmodel to view -

i have windows phone 8.1 silverlight application, , i'm using mvvmlight toolkit. have 3 viewmodel: main, pivotitem , item. in mainviewmodel have observablecollection of pivotitem, , in pivotitemviewmodel observablecollection of itemviewmodel , in itemviewmodel have properties item.

this mainpage.xaml:

<phone:pivot title="{binding title}" itemssource="{binding pivotitemviewmodels}"> <phone:pivot.headertemplate> <datatemplate> <textblock text="{binding header}" /> </datatemplate> </phone:pivot.headertemplate> <phone:pivot.itemtemplate> <datatemplate> <phone:longlistselector x:name="longlistselector" itemssource="{binding itemviewmodels}"> <phone:longlistselector.itemtemplate> <datatemplate> <stackpanel> <textblock text="{binding tipus}" /> <textblock text="{binding megjegyzes}" /> </stackpanel> </datatemplate> </phone:longlistselector.itemtemplate> <i:interaction.triggers> <i:eventtrigger eventname="tap"> <commands:eventtocommand command="{binding selectedcommand, mode=oneway}" commandparameter="{binding path=selecteditem, elementname=longlistselector}" passeventargstocommand="false" /> </i:eventtrigger> </i:interaction.triggers> </phone:longlistselector> </datatemplate> </phone:pivot.itemtemplate> </phone:pivot>

and longlistselector tap event want pass selected item editview.

here selectedcommand in pivotitemviewmodel:

public relaycommand<itemviewmodel> selectedcommand { get; set; } private void edit(itemviewmodel item) { applicationcontroller.default.navigateto(viewtype.edit); } public pivotitemviewmodel() { selectedcommand = new relaycommand<itemviewmodel>(edit); }

my first question viewmodel should use, pivotitemviemmodel or itemviewmodel editview's datacontext? , how pass selected item view ?

c# silverlight mvvm-light

No comments:

Post a Comment