Hi,
Could you please help me to achive Auto-Scrolling on XamWebTree after dragging a node from one parent to another,.
Thanks
Samir
Hi Samir,
The XamWebTree currently does not support this scenario (Autoscrolling when dragging).
However, there is a full set of events which you could probably use to implement such behavior, e.g. the ItemDragMove event.
HTH,
Thanks for your response.
Could you me please help me to provide sample code for same.
Please, check the attached project for a sample. Note that this is only a sample solution which may help you start.
The main code is in the ItemDragMove event handler of the XWTree:
private void XamWebTree_ItemDragMove(object sender, DragMoveEventArgs e)
{
const int offset = 10;
Rect treeBounds;
Rect dragScrollArea;
XamWebTree tree = sender as XamWebTree;
List<XamWebTreeItem> items = new List<XamWebTreeItem>();
bool isDragUp = true;
XamWebTreeItem treeItem = null;
// determine the bounds of the area in which the tree is visualized
treeBounds =
this.GetBounds(tree);
// define an area for which causes scroll up while dragging
dragScrollArea = treeBounds;
dragScrollArea.Height = offset;
// check if the mouse position is in that area,
// if not define area for scrolling down while dragging
if (!dragScrollArea.Contains(e.CursorPosition))
isDragUp =
false;
dragScrollArea.Y = treeBounds.Y + treeBounds.Height - offset;
}
// check if the mouse position is in the scroll area set above,
// if yes, find the outermost tree item and invoke ScrollIntoView
if (dragScrollArea.Contains(e.CursorPosition))
// find all UI elements in the scroll area and filter tree items only
items.AddRange(
VisualTreeHelper.FindElementsInHostCoordinates(dragScrollArea, tree)
.Where(o => o
is XamWebTreeItem)
.Cast<
XamWebTreeItem>()
);
// if there is at least one tree item ...
try
treeItem = items.First();
catch (InvalidOperationException ex)
return;
// ... perform finding the outermost tree item by its Y coordinate
if (isDragUp)
items.ForEach((el) => {
if (this.GetBounds(treeItem).Y > this.GetBounds(el).Y) treeItem = el; });
else
if (this.GetBounds(treeItem).Y < this.GetBounds(el).Y) treeItem = el; });
// NOTE: the next item to be scrolled seems to be always found with the algorithm above,
// so just scroll it into view
treeItem.ScrollItemIntoView();
Hi Gerenski,
Thanks for your help and support.
But given solution is not 100%.
Is it possible to implement New Drag & Drop Framework with Tree View.
Thanks...
I am sending you a sample for how this could be done, but please also keep in mind that those are only quick solutions to demonstrate one of the options that comes to my mind.
Please, see the attached solution.
Hi Stoimen Gerenski,
The above Solution works fine for my requirement. Thanks for your Help.Here we are facing one more problem while Draginng a item to Target Folder.Issue Description:If we drag an item to Target Folder where Target Folder may Contain Another Child Folder which is collapsed at that moment, So in this Case we need to expand the Target Folder on Dragging one item to target Folder so that we can see what are all the Child Folders existed in that target folder to place the Draaged item to child Folder.Simply i want Target folder to get expanded when item is dragged on it.Please advice us for above issue. If possible Please provide Sample Code.Cheers,Samir
Please check the attached solution.
Regards,
Thanks & Really appreciate your quick response.
I am using silverlight and unable to get GetBounds().
Please help