public static void SetHasBindableSelectedItems(ListBox source, bool value) { SelectionChangedHandler Handler = (SelectionChangedHandler)source.GetValue(SelectionChangedHandlerProperty); if (value && Handler == null) { Handler = new SelectionChangedHandler(source); source.SetValue(SelectionChangedHandlerProperty, Handler); } else if (!value && Handler != null) { source.ClearValue(SelectionChangedHandlerProperty); } }
public static void SetHasBindableSelectedItems(System.Windows.Controls.ListBox source, bool value) { var handler = (SelectionChangedHandler)source.GetValue(SelectionChangedHandlerProperty); if (value && handler == null) { handler = new SelectionChangedHandler(source); source.SetValue(SelectionChangedHandlerProperty, handler); } else if (!value && handler != null) { source.ClearValue(SelectionChangedHandlerProperty); } }
private void DragStarted(ListBox listbox) { listbox.ClearValue(IsDownProperty); // SetValue to false would also work. // Add the bound item, available as DraggingElement, to a DataObject, however we see fit. Artist draggingElement = (Artist)listbox.GetValue(DraggingElementProperty); DataObject d = new DataObject(DataFormats.Dif, draggingElement); DragDropEffects effects = DragDrop.DoDragDrop(listbox, d, DragDropEffects.Copy); if ((effects & DragDropEffects.Move) != 0) { // Move rather than copy, so we should remove from bound list. DataList<Artist> collection = (DataList<Artist>)listbox.ItemsSource; collection.Remove(draggingElement); } }