Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF ListBox drag & drop interferes with ContextMenu?
    primarykey
    data
    text
    <p>I'm implementing drag &amp; drop from a ListBox, but I'm seeing some strange behaviour with a ContextMenu elsewhere in the window. If you open the context menu and then start a drag from the ListBox, the context menu closes but won't open again until after you perform another drag.</p> <p>Does this make sense? Anybody got any ideas what might be going on?</p> <pre><code>&lt;ListBox Grid.Row="0" ItemsSource="{Binding SourceItems}" MultiSelectListboxDragDrop:ListBoxExtension.SelectedItemsSource="{Binding SelectedItems}" SelectionMode="Multiple" PreviewMouseLeftButtonDown="HandleLeftButtonDown" PreviewMouseLeftButtonUp="HandleLeftButtonUp" PreviewMouseMove="HandleMouseMove"/&gt; &lt;ListBox Grid.Row="1" ItemsSource="{Binding DestinationItems}" AllowDrop="True" Drop="DropOnToDestination" /&gt; &lt;Button Grid.Row="2"&gt; &lt;Button.ContextMenu&gt; &lt;ContextMenu x:Name="theContextMenu"&gt; &lt;MenuItem Header="context 1"/&gt; &lt;MenuItem Header="context 2"/&gt; &lt;MenuItem Header="context 3"/&gt; &lt;/ContextMenu&gt; &lt;/Button.ContextMenu&gt; Button with context menu &lt;/Button&gt; </code></pre> <p>...</p> <pre><code>public partial class Window1 { private bool clickedOnSourceItem; public Window1() { InitializeComponent(); DataContext = new WindowViewModel(); } private void DropOnToDestination(object sender, DragEventArgs e) { var viewModel = (WindowViewModel)e.Data.GetData(typeof(WindowViewModel)); viewModel.CopySelectedItems(); } private void HandleLeftButtonDown(object sender, MouseButtonEventArgs e) { var sourceElement = (FrameworkElement)sender; var hitItem = sourceElement.InputHitTest(e.GetPosition(sourceElement)) as FrameworkElement; if(hitItem != null) { clickedOnSourceItem = true; } } private void HandleLeftButtonUp(object sender, MouseButtonEventArgs e) { clickedOnSourceItem = false; } private void HandleMouseMove(object sender, MouseEventArgs e) { if(clickedOnSourceItem) { var sourceItems = (FrameworkElement)sender; var viewModel = (WindowViewModel)DataContext; DragDrop.DoDragDrop(sourceItems, viewModel, DragDropEffects.Move); clickedOnSourceItem = false; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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