c# - ListView.SelectedItem passing to ViewModel as CommandParameter WindowsRT XAML -
i have viewmodel defines relaycommand , in view defined listview listitemtemplate. need clicking on list item invoke command value of list item.
listview in view
<listview x:name="listview1" selectionmode="single" itemssource="{binding similarartists}" minwidth="360"> <interactivity:interaction.behaviors> <core:eventtriggerbehavior eventname="selectionchanged"> <core:invokecommandaction command="{binding resolvesearchpageviewmodel.searchcommand, converter={staticresource selectionchangedconverter}, mode=oneway, source={staticresource locator}}" inputconverterparameter="{binding elementname=listview1}" /> </core:eventtriggerbehavior> </interactivity:interaction.behaviors> <listview.itemtemplate> <datatemplate> <grid minwidth="360"> <grid.columndefinitions> <columndefinition maxwidth="48"/> <columndefinition minwidth="360"/> </grid.columndefinitions> <image grid.column="0" width="48" source="../assets/singer.png"/> <grid grid.column="1"> <grid.rowdefinitions> <rowdefinition/> <rowdefinition/> </grid.rowdefinitions> <textblock margin="10, 10, 0, 10" fontsize="25" text="{binding name}" textwrapping="wrap" grid.row="0"/> </grid> </grid> </datatemplate> </listview.itemtemplate> </listview>
selectionchangedconverter
public class selectionchangedconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, string language) { var listview = parameter listview; return listview.selecteditem; } public object convertback(object value, type targettype, object parameter, string language) { throw new notimplementedexception(); } }
relaycommand
gotosearchpagecommand = new relaycommand<artist>((item) => { var = item; _pagenavigationservice.toloadingpage(item.name); });
i need pass in relaycommand value of selecteditem , invoke command. thank you. best regards, dmitry
ps. english not good, i'm sorry.
have considered binding selecteditem property of listview view-model's property?
you don't need command. selecteditem mapped long declare binding it.
just add property view-model reflects type itemssource based on , bind in xaml.
<listview selecteditem = "{binding myselecteditem}"
Comments
Post a Comment