DragVisualProvider mouse visual offset

4 posts, 0 answers
  1. Terry
    Terry avatar
    17 posts
    Member since:
    Mar 2013

    Posted 08 Apr 2013 Link to this post

    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
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 11 Apr 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Terry
    Terry avatar
    17 posts
    Member since:
    Mar 2013

    Posted 11 Apr 2013 Link to this post

    Thank you, but that doesn't SET the offset on the DragVisual. As I mentioned, DragVisualProviderState already provides this relativeoffset.
  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 16 Apr 2013 Link to this post

    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.

Back to Top