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:

  1. name listbox
  2. update commandparameter to:

    commandparameter="{binding elementname=listbox1,path=selecteditem}"


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -