Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to rearrange the items in treeview(wpf, c#) by drag and drop, as in the following link: jQuery UI Sortable - Drop placeholder[^] . I could able to achieve till this:- Showing the dragged item along with mouse and able to drop at the place where I want(rearrange also happening), but couldn't able to achieve by having a placeholder(mentioned in the above link). Did a lot of search, but couldn't find anything match with my requirements. I think, I need to play with my adorner, to acheive this. Can someone give me some ideas how to do it

What I have tried:

Here is the adorner class, which I am using
C#
public class DragAdorner : Adorner
   {
       public DragAdorner(UIElement owner) : base(owner)
       {
           IsHitTestVisible = false;
       }
       public DragAdorner(UIElement owner, UIElement adornElement, bool useVisualBrush, double opacity) : base(owner)
       {
           _owner = owner;
           VisualBrush _brush = new VisualBrush
           {
               Opacity = opacity,
               Visual = adornElement
           };
           System.Windows.Media.Animation.DoubleAnimation animation = new System.Windows.Media.Animation.DoubleAnimation(0.3, 1, new Duration(TimeSpan.FromSeconds(1)));
           animation.AutoReverse = true;
           animation.RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;
           _brush.BeginAnimation(System.Windows.Media.Brush.OpacityProperty, animation);
           DropShadowEffect dropShadowEffect = new DropShadowEffect
           {
               Color = Colors.Black,
               BlurRadius = 15,
               Opacity = opacity
           };
           Rectangle r = new Rectangle
           {
               RadiusX = 3,
               RadiusY = 3,
               Fill = _brush,
               Effect = dropShadowEffect,
               Width = adornElement.DesiredSize.Width,
               Height = adornElement.DesiredSize.Height
           };
           XCenter = adornElement.DesiredSize.Width / 2;
           YCenter = adornElement.DesiredSize.Height / 2;
           _child = r;
       }
       private void UpdatePosition()
       {
           AdornerLayer adorner = (AdornerLayer)Parent;
           if (adorner != null)
           {
               adorner.Update(AdornedElement);
           }
       }
       #region Overrides
       protected override Visual GetVisualChild(int index)
       {
           return _child;
       }
       protected override int VisualChildrenCount
       {
           get
           {
               return 1;
           }
       }
       protected override Size MeasureOverride(Size finalSize)
       {
           _child.Measure(finalSize);
           return _child.DesiredSize;
       }
       protected override Size ArrangeOverride(Size finalSize)
       {

           _child.Arrange(new Rect(_child.DesiredSize));
           return finalSize;
       }
       public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
       {
           GeneralTransformGroup result = new GeneralTransformGroup();
           result.Children.Add(base.GetDesiredTransform(transform));
           result.Children.Add(new TranslateTransform(_leftOffset, _topOffset));
           return result;
       }
       #endregion
       #region Field & Properties
       public double scale = 1.0;
       protected UIElement _child;
       protected VisualBrush _brush;
       protected UIElement _owner;
       protected double XCenter;
       protected double YCenter;
       private double _leftOffset;
       public double LeftOffset
       {
           get { return _leftOffset; }
           set
           {
               _leftOffset = value - XCenter;
               UpdatePosition();
           }
       }
       private double _topOffset;
       public double TopOffset
       {
           get { return _topOffset; }
           set
           {
               _topOffset = value - YCenter;
               UpdatePosition();
           }
       }
       #endregion
   }
Posted
Updated 19-Sep-19 3:55am
v2
Comments
[no name] 19-Sep-19 17:59pm    
What's the point of a "place holder"? And the picture of your "tree view" / ? looks like a "list view".
Priya Karthish 20-Sep-19 7:18am    
My first node of the treeview has items (child)only at the same level. I am doing a rearrange process for the items in that level. My client wanted to have to do the rearrange process as in the link. I am confused whether it is possible or not as it is text block, but they want it in that pattern.(as in the link)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900