Ejemplo n.º 1
0
        private void ScrollViewer_Drop(object sender, DragEventArgs e)
        {
            string data = (string)e.Data.GetData(DataFormats.Text);

            if (data.Contains("Materia::Layer::"))
            {
                Point  p      = e.GetPosition(ScrollView);
                double offset = ScrollView.VerticalOffset;
                double realY  = offset + p.Y;

                LayerItem orig = LayerStack.Children.OfType <LayerItem>().FirstOrDefault(m => data.Contains(m.Item.Id));

                if (orig == null)
                {
                    return;
                }

                LayerStack.Children.Remove(orig);

                bool added = false;

                for (int i = 0; i < LayerStack.Children.Count; ++i)
                {
                    LayerItem item = LayerStack.Children[i] as LayerItem;
                    if (item == null)
                    {
                        continue;
                    }
                    if (item == orig)
                    {
                        continue;
                    }
                    Point relative = item.TransformToAncestor(LayerStack).Transform(new Point(0, 0));
                    if (realY >= relative.Y && realY <= relative.Y + item.ActualHeight)
                    {
                        LayerStack.Children.Insert(i, orig);

                        //update graph layer data as well
                        Current.Layers.Remove(orig.Item);
                        Current.Layers.Insert(i, orig.Item);

                        added = true;
                        break;
                    }
                }

                if (!added)
                {
                    LayerStack.Children.Add(orig);
                    Current.Layers.Remove(orig.Item);
                    Current.Layers.Add(orig.Item);
                }

                Current?.CombineLayers();
            }
        }