0down votefavorite | am trying to do a drag and drop of an expander from the lisbox "faire" to the listbox "cours" using this code: private void faire_MouseUp(object sender, MouseButtonEventArgs e) { ListBoxItem i = sender as ListBoxItem; DataObject data = new DataObject(typeof(ListBoxItem)); DragDropEffects dde1 = DragDrop.DoDragDrop(_dragged, data, DragDropEffects.Move); } private void faire_MouseDown(object sender, MouseButtonEventArgs e) { ListBoxItem i = sender as ListBoxItem; DataObject data = new DataObject(typeof(ListBoxItem), i); DragDropEffects dde1 = DragDrop.DoDragDrop(_dragged, data, DragDropEffects.Move); } private void cours_DragEnter(object sender, DragEventArgs e) { if (_dragged == null) e.Effects = DragDropEffects.None; else e.Effects = DragDropEffects.All; } private void cours_Drop(object sender, DragEventArgs e) { ListBox parent = (ListBox)sender; object data = e.Data.GetData(typeof(Expander)); faire.Items.Remove(data); parent.Items.Add(data); } private void faire_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ListBox parent = (ListBox)sender; dragSource = parent; object data = GetDataFromListBox(dragSource, e.GetPosition(parent)); if (data != null) { DragDrop.DoDragDrop(parent, data, DragDropEffects.Move); } } #region GetDataFromListBox(ListBox,Point) private static object GetDataFromListBox(ListBox source, Point point) { UIElement element = source.InputHitTest(point) as UIElement; if (element != null) { object data = DependencyProperty.UnsetValue; while (data == DependencyProperty.UnsetValue) { data = source.ItemContainerGenerator.ItemFromContainer(element); if (data == DependencyProperty.UnsetValue) { element = VisualTreeHelper.GetParent(element) as UIElement; } if (element == source) { return null; } } if (data != DependencyProperty.UnsetValue) { return data; } } return null; } #endregion the drag is working but i cant expand the expander anymore what should i do ? ` |
Loading
Replies
Know the answer? Post it — somebody with the same question will find it here.