Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF - treeview - drag and drop and contextmenu issue
    text
    copied!<p>I have a TreeView. I set a ContextMenu on the TreeViewItems. When I open the ContextMenu by rightclicking on an item and select another item (while the ContextMenu is open) I expect the just clicked item to get selected without doing anything. Instead the Framework thinks that I want to drag the item on which the ContextMenu was opened and therefor calls the Drop handler. How can I solve this problem. Thanks</p> <pre><code> private void TreeViewPreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed &amp;&amp; !_isDragging) { var position = e.GetPosition(sender as IInputElement); if (Math.Abs(position.X - _startPoint.X) &gt; SystemParameters.MinimumHorizontalDragDistance || Math.Abs(position.Y - _startPoint.Y) &gt; SystemParameters.MinimumVerticalDragDistance) { StartDrag(); } } } private void TreeViewPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { _startPoint = e.GetPosition(sender as IInputElement); } private void TemplateTreeViewDrop(object sender, DragEventArgs e) { if (_isDragging &amp;&amp; (e.Source as TreeView) != null) { dragQuestion = e.Data.GetData(typeof(QuestionListItem)) as QuestionListItem; dropQuestion = GetItemAtLocation(e.GetPosition(TemplateTreeView)); if (dragQuestion != null &amp;&amp; dropQuestion != null &amp;&amp; dragQuestion!=dropQuestion) { viewModel.MoveQuestion(dragQuestion, dropQuestion); } } e.Handled = true; dragQuestion = null; } private void StartDrag() { var temp = TemplateTreeView.SelectedItem as QuestionListItem; if(temp == null) return; _isDragging = true; var data = new DataObject(temp); DragDrop.DoDragDrop(TemplateTreeView, data, DragDropEffects.Move); _isDragging = false; } </code></pre>
 

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