滚动而拖放(WPF) [英] Scrolling while dragging and dropping (WPF)
问题描述
好球员,我一直在抓我的头疯狂过这一问题,并已经花了好几个小时,试图研究它是如何工作的,但我还没有找到一个答案,如果你想看到我的任何SRC的随意问一下,我会看看我可以提供帮助。
基本上我遇到的问题是,我有一个 TreeView控件
在我的应用程序,即文件夹:
目录
品牌
耐克
阿迪达斯
乳糖
曲风
Sandles
教练
靴
这是我想解决的问题是,当我将一个文件夹各地(这是在我的 DragDropManager
类处理) ,我无法或上下滚动(只显示一个可爱的停车标志)。我也无法将树视图中居然找到一个滚动条,所以我不清楚是如何被创造它(这不是我自己的软件,我最近开始为一家公司工作,所以我不熟悉的代码并没有其他人似乎知道。)
这是一个问题,如果我想从最顶部移动的东西到最底部。
的
滚动运行在拥有精致而不进行拖动。
如果任何人希望看到我的代码任何部分随意问,因为我不确定什么实际显示你们。
我走过了好几篇文章读和我刚刚离开抓我的头。
我已经创造了实现这一行为的附加属性,看看我的文章在这里 -
主要逻辑是这样的 -
私有静态无效OnContainerPreviewDragOver(对象发件人,DragEventArgs E)
{
FrameworkElement的容器=发件人为FrameworkElement的;
如果(集装箱== NULL)
{
的回报;
}
的ScrollViewer的ScrollViewer = GetFirstVisualChild<&的ScrollViewer GT;(容器);
如果(的ScrollViewer == NULL)
{
的回报;
}
双宽容= 60;
双verticalPos = e.GetPosition(集装箱).Y;
双胶纸= 20;
如果(verticalPos<公差)//顶部可见名单?
{
//向上滚动
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - 偏移);
}
,否则如果(verticalPos> container.ActualHeight - 公差)//可见列表的底部?
{
//向下滚动
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset +偏移量);
}
}
这是如此的相似问题(尽管它们大多为的ListBox
/ 的ListView
,但应适用 TreeView控件
太) - <同时拖动/ p>
工作
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屋!