The previous option is to be processed when the SelectionChanged event of the listbox is triggered. However, the ListBox has no previewselectionchanged events.
Workaround:
1. Validation
Because the item to be processed is in a textbox, you can add a validation to the textbox. However, because the textbox is binding to the property, and validation is operated before the binding assignment (this is the process during debugging), the value in the TextBox cannot be obtained. If there is no binding it should be possible.
Reference: https://social.msdn.microsoft.com/Forums/vstudio/en-US/e96c725e-a86d-427e-944b-fcc4273ac260/ Any-way-to-preview-the-listviewselectionchanged-event?forum=wpf
2. Get the Removeditem in SelectionChangedEventArgs. Finally, this method is used.
private void ListBox_SelectionChanged(object sender , SelectionChangedEventArgs e){ // Here are your old selected items from the selection changed. // If your list box does not allow multiple selection, then just use the index 0 // but making sure that the e.RemovedItems.Count is > 0 if you are planning to address by index. IList oldItems = e.RemovedItems; // Do something here. // Here are you newly selected items. IList newItems = e.AddedItems;}
参考:http://stackoverflow.com/questions/1548237/how-to-get-something-like-previewselectionchanged-event-in-listbox
WPF Tips:listbox selectionchanged Pre-trigger options