Exemple #1
0
 void HidePreview()
 {
     if (previewNodeView != null)
     {
         previewNodeView.ClearValue(SharpTreeNodeView.TextBackgroundProperty);
         //previewNodeView.ClearValue(SharpTreeNodeView.ForegroundProperty);
         if (insertMarker != null)
         {
             insertMarker.IsVisible = false;
         }
         previewNodeView = null;
     }
 }
Exemple #2
0
        void ShowPreview(SharpTreeViewItem item, DropPlace place)
        {
            previewNodeView = item.NodeView;
            previewPlace    = place;

            if (place == DropPlace.Inside)
            {
                previewNodeView.TextBackground = SystemColors.HighlightBrush;
                //previewNodeView.Foreground = SystemColors.HighlightTextBrush;
            }
            else
            {
                if (insertMarker == null)
                {
                    var adornerLayer = AdornerLayer.GetAdornerLayer(this);
                    insertMarker = new InsertMarker();
                    var adorner = new AdornerDecorator()
                    {
                        Child = insertMarker
                    };
                    adornerLayer.Children.Add(adorner);
                }

                insertMarker.IsVisible = true;

                var p1 = previewNodeView.TranslatePoint(new Point(), this);
                var p  = new Point(p1.X + previewNodeView.CalculateIndent() + 4.5, p1.Y - 3);

                if (place == DropPlace.After)
                {
                    p = p.WithY(p.Y + previewNodeView.Height);
                }

                insertMarker.Margin = new Thickness(p.X, p.Y, 0, 0);

                SharpTreeNodeView secondNodeView = null;
                var index = flattener.IndexOf(item.Node);

                if (place == DropPlace.Before)
                {
                    if (index > 0)
                    {
                        secondNodeView = (ItemContainerGenerator.ContainerFromIndex(index - 1) as SharpTreeViewItem).NodeView;
                    }
                }
                else if (index + 1 < flattener.Count)
                {
                    secondNodeView = (ItemContainerGenerator.ContainerFromIndex(index + 1) as SharpTreeViewItem).NodeView;
                }

                var w = p1.X + previewNodeView.Width - p.X;

                if (secondNodeView != null)
                {
                    var p2 = secondNodeView.TranslatePoint(new Point(), this);
                    w = Math.Max(w, p2.X + secondNodeView.Width - p.X);
                }

                insertMarker.Width = w + 10;
            }
        }