Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Normally, in MVVM, if you bound the <strong>Command</strong>, you could pass a <strong>CommandParameter</strong> and in it put the <strong>DataContext</strong>, but the MOST <strong>important</strong> thing to do is to pass the "<strong>DataContext</strong>". since this is tied to a Click event, typecast the sender as a button, acess the DataContext and this should be the object in the listbox. So if your listbox is bound to an <strong>ItemsSource</strong> of "Customers", your "<strong>DataContext</strong>" on the button should be a "Customer" object. It should be passed down since the StackPanel's DataContext will be that object, and all it's children should have the same. E.g.:</p> <pre><code>public void btnClearBodyMark_Click(object sender, ButtonClickEventArgs e) { var myRef = (sender as Button).DataContext; } </code></pre> <p>Something like that.<br> P.S. since this is most likely bound to a set of "objects". The item is no longer a ListBoxItem per say, but rather a datatype of the bound collection.<br> Also, you can save yourself the work of "SelectionChanged" event if you bound the <strong>SelectedItem</strong> property of the ListBox to a property in your ViewModel, with a mode of <strong>Mode=TwoWay</strong>. Make sure that your property, for example "SelectedListItem" in the ViewModel notifies the property changed event by ensuring that your ViewModel implements INotifyPropertyChanged which is found in System.ComponentModel i think. That way, once the user selects something, there's no need for an even handler ;).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload