Skip to content

Commit

Permalink
fixed drag & drop bug
Browse files Browse the repository at this point in the history
  • Loading branch information
milleniumbug committed Feb 13, 2017
1 parent b026b8a commit ce1d892
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TaxonomyWpf/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<TextBlock Text="{Binding Namespace.Component}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type taxonomyLib:Tag}">
<TextBlock Text="{Binding Name.Name}">
<TextBlock Background="Transparent" Text="{Binding Name.Name}">
<TextBlock.InputBindings>
<MouseBinding
Command="{Binding TagDoubleClick, RelativeSource={RelativeSource AncestorType=Window}}"
Expand Down
14 changes: 7 additions & 7 deletions TaxonomyWpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@ private void OpenTaxonomyClick(object sender, RoutedEventArgs e)
}

private Point? tagClickStartPoint;
private FrameworkElement draggedItem;

private void TagPreviewLeftButtonDown(object sender, MouseButtonEventArgs e)
{
tagClickStartPoint = e.GetPosition(null);
// Get the dragged item
var treeView = (TreeView)sender;
draggedItem =
FindAnchestor<TextBlock>((DependencyObject)e.OriginalSource);

This comment has been minimized.

Copy link
@JohanLarsson

JohanLarsson Feb 13, 2017

s/FindAnchestor/FindAncestor typo

This comment has been minimized.

Copy link
@milleniumbug

milleniumbug Feb 13, 2017

Owner

@JohanLarsson Right. The original example had it too and somehow I thought it was actually called that. Fixing.

}

private void TagPreviewMouseMove(object sender, MouseEventArgs e)
Expand All @@ -119,20 +124,15 @@ private void TagPreviewMouseMove(object sender, MouseEventArgs e)
Math.Abs(distance.X) > SystemParameters.MinimumHorizontalDragDistance &&
Math.Abs(distance.Y) > SystemParameters.MinimumVerticalDragDistance)
{
// Get the dragged ListViewItem
var treeView = (TreeView)sender;
var item =
FindAnchestor<TextBlock>((DependencyObject)e.OriginalSource);

// Find the data behind the ListViewItem
var tag = item?.DataContext as Tag;
var tag = draggedItem?.DataContext as Tag;

if(tag == null)
return;

// Initialize the drag & drop operation
var dragData = new DataObject(typeof(Tag), tag);
DragDrop.DoDragDrop(item, dragData, DragDropEffects.Move);
DragDrop.DoDragDrop(draggedItem, dragData, DragDropEffects.Move);

tagClickStartPoint = null;
}
Expand Down

0 comments on commit ce1d892

Please sign in to comment.