wpf - How to pass listbox selecteditem as command parameter in a button? -
here situation:
<listbox itemssource="{binding path=availableusers}"> <listbox.itemtemplate> <datatemplate> <textblock text="{binding path=id}"/> </datatemplate> </listbox.itemtemplate> </listbox> <button command="{binding path=load}" commandparameter={???? goes here ????}/>
what want pass id selected in listbox. have viewmodel behind scenes looks this:
public class viewmodel : dependencyobject { icommand load { get; set; } // dependency property didn't bother write out 1 list<user> availableusers { get; set} }
how can send selected item using xaml?
try this:
- name listbox
- update commandparameter to:
commandparameter="{binding elementname=listbox1,path=selecteditem}"
Comments
Post a Comment