拖放时滚动(WPF) [英] Scrolling while dragging and dropping (WPF)

查看:192
本文介绍了拖放时滚动(WPF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我一直在这个问题上一直在scratch ing我的头像,而且花了好几个小时试图研究它是如何工作的,但我还没有找到答案,如果你希望看到我的任何一个SRC感到自由要查询它,我会看看是否可以帮助。



基本上我遇到的问题是我有一个 TreeView 我的应用程序中的文件夹ie:

 目录

品牌
耐克
阿迪达斯
乳糖

样式
砂带
培训师
靴子

我想要修复的问题是当我拖动一个文件夹(这是在我的 DragDropManager 类中处理) ,我无法向上或向下滚动(只显示可爱的停车标志)。我也不能在树视图中找到一个滚动条,所以我不确定它是如何生成的(这不是我自己的软件,我最近开始为一家公司工作,所以我不熟悉代码,没有人似乎知道。)



如果我想将东西从顶部移到底部,这是一个问题。



如果有任何人希望看到我的代码的任何部分,我可以自由地询问,因为我不确定,滚动可以自行工作,而不用拖动。



实际上显示你们的人物。



我已阅读了很多文章,只是让我头疼。

解决方案

我已经创建了附带的属性来实现这个行为,看看我的帖子 -



附加B自动滚动容器的行为,同时做Drag&下拉



主要逻辑是这样的 -

  private static void OnContainerPreviewDragOver(object sender,DragEventArgs e)
{
FrameworkElement container = sender as FrameworkElement;

if(container == null)
{
return;
}

ScrollViewer scrollViewer = GetFirstVisualChild&ScrollViewer>(container);

if(scrollViewer == null)
{
return;
}

双重容差= 60;
double verticalPos = e.GetPosition(container).Y;
double offset = 20;

if(verticalPos< tolerance)//可见列表顶部?
{
//向上滚动
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - offset);
}
else if(verticalPos> container.ActualHeight - tolerance)//底部的可见列表?
{
//向下滚动
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + offset);
}
}

关于SO的类似问题(尽管它们主要用于 ListBox / ListView ,但应适用于 TreeView ) -



WPF Listbox在拖动时自动滚动



WPF ListView数据绑定拖放自动滚动



WPF拖动到滚动无法正常工作


Okay guys, I have been scratching my head like mad over this issue and have spent a good few hours trying to research how it works but I am yet to find an answer, if you wish to see any of my SRC feel free to ask about it and I will see if I can help.

Basically the issue I am having is that I have a TreeView of folders in my application i.e:

Catalog

  Brands
    Nike
    Adidas
    Lactose

  Styles
    Sandles
    Trainers
    Boots

The issue that I am trying to fix is that when I drag a folder around (This is handled in my DragDropManager class), I am unable to scroll up or down(simply displays a lovely stop sign). I am also unable to find a scroller actually within the treeview, so I am unsure how it is being generated (This is not my own software, I have recently started working for a company so I am not familiar with the code and no one else seems to know.)

This is a problem if I want to move something from the very top to the very bottom.

The scrolling works fine on its own without the dragging being done.

If anyone wishes to see any part of my code feel free to ask as I am unsure what to actually show you guys.

I have read through a good few articles and am just left scratching my head.

解决方案

I have created an attached property for achieving this behavior, have a look at my post here -

Attached Behavior for auto scrolling containers while doing Drag & Drop

Main logic is something like this -

private static void OnContainerPreviewDragOver(object sender, DragEventArgs e)
{
    FrameworkElement container = sender as FrameworkElement;

    if (container == null)
    {
        return;
    }

    ScrollViewer scrollViewer = GetFirstVisualChild<ScrollViewer>(container);

    if (scrollViewer == null)
    {
        return;
    }

    double tolerance = 60;
    double verticalPos = e.GetPosition(container).Y;
    double offset = 20;

    if (verticalPos < tolerance) // Top of visible list? 
    {
        //Scroll up
        scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - offset);
    }
    else if (verticalPos > container.ActualHeight - tolerance) //Bottom of visible list? 
    {
        //Scroll down
        scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + offset);     
    }
}

Similar questions on SO (although they are mostly for ListBox/ListView but should work for TreeView too) -

WPF Listbox auto scroll while dragging

WPF ListView Databound Drag/Drop Auto Scroll

WPF Drag-to-scroll doesn't work correctly

这篇关于拖放时滚动(WPF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆