This is a migrated thread and some comments may be shown as answers.

DragVisualProvider mouse visual offset

3 Answers 96 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 08 Apr 2013, 09:27 PM
Hello,

I'm using a custom DragVisualProvider with the ListBoxDragDropBehavior and I can't seem to figure out how to offset the mouse position within the dragVisual. I know you can get the RelativeStartPoint from DragVisualProviderState, but how do you set that on the newly created dragVisual (ContentControl, in this case). 

Here is my custom DragVisualProvider code:

public FrameworkElement CreateDragVisual(DragVisualProviderState state)
{
     
    var visual = new ContentControl();
     
    var theme = StyleManager.GetTheme(state.Host);
    if (theme != null)
    {
        StyleManager.SetTheme(visual, theme);
    }
 
    var draggedItem = state.DraggedItemContainers.First() as FrameworkElement;
    visual.Height = draggedItem.ActualHeight;
    visual.Width = draggedItem.ActualWidth;
     
    visual.Content = state.DraggedItems.OfType<object>().FirstOrDefault();
    visual.ContentTemplate = this.DragVisualTemplate;
     
    return visual;
}

Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 11 Apr 2013, 11:11 AM
Hi,

In order to set the DragVisualOffset in your custom DragVisualProvider your class should implement IDragVisualProvider interface and implement its GetDragVisualOffset method, in that method you can return the desired offset.

The next code snippet represents a sample custom DragVisualProvider:
public class CustomDragVisualProvider : IDragVisualProvider
{
    public System.Windows.FrameworkElement CreateDragVisual(DragVisualProviderState state)
    {
        var visual = new ContentControl();
        var draggedItem = state.DraggedItemContainers.First() as FrameworkElement;
        visual.Height = draggedItem.ActualHeight;
        visual.Width = draggedItem.ActualWidth;
        visual.Content = state.DraggedItems.OfType<object>().FirstOrDefault();
 
        return visual;
    }
 
    public System.Windows.Point GetDragVisualOffset(DragVisualProviderState state)
    {
        Point offset = new Point(100, 1);
 
        return offset;
    }
 
    public bool UseDefaultCursors
    {
        get { return false; }
    }
}

Hope this is helpful.

Kind regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Terry
Top achievements
Rank 1
answered on 11 Apr 2013, 03:28 PM
Thank you, but that doesn't SET the offset on the DragVisual. As I mentioned, DragVisualProviderState already provides this relativeoffset.
0
Vladi
Telerik team
answered on 16 Apr 2013, 12:28 PM
Hello,

I am not sure what you mean by "set the offset on the DragVisual". If you return in the GetDragVisualOffset method a Point object, that object represents the offset that will be set to the DragVisual. I recorded and attached a short video for you showing that the custom DragVisual has an offset set to it from that method.

If we have missed something could you describe to us in more details what exactly are you trying to achieve. Could you try to illustrate the desired approach in a sample project and send us that project in a new support thread?

Kind regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ListBox
Asked by
Terry
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Terry
Top achievements
Rank 1
Share this question
or