Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,
I have a question 'how to cancel drag.'

In my case. when customer drag treeViewItem to target, show messageBox, if 'Cancel' button click, give up drag operation.

Follow is my code, but it dose not work.pls help!

XAML:
HTML
   <my:TreeViewDragDropTarget x:Name="tvddtCategroy" AllowDrop="true" AllowedSourceEffects="Move" ItemDroppedOnTarget="tvddtCategroy_ItemDroppedOnTarget">
      <controls:TreeView x:Name="tvCategory" BorderBrush="White" AllowDrop="True" 
      </controls:TreeView>
</my:TreeViewDragDropTarget>


C#:
C#
private void tvddtCategroy_ItemDroppedOnTarget(object sender, ItemDragEventArgs e)
        {
            if (MessageBox.Show("Are you sure to move this category?", "", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                e.Cancel = true;
                e.Handled = true;
            }
        }
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900