Issues with DragAdornerBehavior
I'm trying to have something follow the mouse while I am dragging, but there are two issues:
1): It seems that the drag only works while the cursor is under another control. If the cursor is not under another control, the control stops following the cursor.
2): The control that follows the cursor is far away from the cursor.
Video: https://files.catbox.moe/n240jv.mp4
This is in a UserControl that is the size of the entire screen.
1): It seems that the drag only works while the cursor is under another control. If the cursor is not under another control, the control stops following the cursor.
2): The control that follows the cursor is far away from the cursor.
Video: https://files.catbox.moe/n240jv.mp4
This is in a UserControl that is the size of the entire screen.
Code: Select all
<Grid>
<b:Interaction.Behaviors>
<noesis:DragAdornerBehavior x:Name="DragAdorner" />
</b:Interaction.Behaviors>
...
<Border Width="25" Height="25">
<Border.RenderTransform>
<TranslateTransform X="{Binding DraggedItemX, ElementName=DragAdorner}" Y="{Binding DraggedItemY, ElementName=DragAdorner}" />
</Border.RenderTransform>
<Image Source="{Binding DraggedCharacter.Icon}" />
</Border>
</Grid>
-
sfernandez
Site Admin
- Posts: 3093
- Joined:
Re: Issues with DragAdornerBehavior
1. The drag operation needs a hit-testable element (at least with a Transparent background) to receive the drag events. So the Grid with the DragAdornerBehavior should have a Background="Transparent" set. Although you can set it only during the drag operation if you still want to click through into the 3D scene behind, something like this:
2. The element that is being moved around in your xaml is centered in the Grid, so that center offset is added to the DraggedItemX/Y coordinates. Just set HorizontalAlignment="Left" and VerticalAlignment="Top" on the Border and it will move with the mouse:
Code: Select all
public void OnDragStart(object param)
{
_dragAdornerGrid.Background = Brushes.Transparent;
// ...
}
public void OnDrop(object param)
{
// ...
_dragAdornerGrid.Background = null;
}
Code: Select all
<Grid>
<b:Interaction.Behaviors>
<noesis:DragAdornerBehavior x:Name="DragAdorner" />
</b:Interaction.Behaviors>
...
<Border Width="25" Height="25" HorizontalAlignment="Left" VerticalAlignment="Center">
<Border.RenderTransform>
<TranslateTransform X="{Binding DraggedItemX, ElementName=DragAdorner}" Y="{Binding DraggedItemY, ElementName=DragAdorner}" />
</Border.RenderTransform>
<Image Source="{Binding DraggedCharacter.Icon}" />
</Border>
</Grid>
Who is online
Users browsing this forum: No registered users and 5 guests